CF1837F.Editorial for Two

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Berland Intercollegiate Contest has just finished. Monocarp and Polycarp, as the jury, are going to conduct an editorial. Unfortunately, the time is limited, since they have to finish before the closing ceremony.

There were nn problems in the contest. The problems are numbered from 11 to nn . The editorial for the ii -th problem takes aia_i minutes. Monocarp and Polycarp are going to conduct an editorial for exactly kk of the problems.

The editorial goes as follows. They have a full problemset of nn problems before them, in order. They remove nkn - k problems without changing the order of the remaining kk problems. Then, Monocarp takes some prefix of these kk problems (possibly, an empty one or all problems). Polycarp takes the remaining suffix of them. After that, they go to different rooms and conduct editorials for their problems in parallel. So, the editorial takes as much time as the longer of these two does.

Please, help Monocarp and Polycarp to choose the problems and the split in such a way that the editorial finishes as early as possible. Print the duration of the editorial.

输入格式

The first line contains a single integer tt ( 1t1041 \le t \le 10^4 ) — the number of testcases.

The first line of each testcase contains two integers nn and kk ( 1kn31051 \le k \le n \le 3 \cdot 10^5 ) — the number of problems in the full problemset and the number of problems Monocarp and Polycarp are going to conduct an editorial for.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n ( 1ai1091 \le a_i \le 10^9 ) — the time each editorial takes.

The sum of nn over all testcases doesn't exceed 31053 \cdot 10^5 .

输出格式

For each testcase, print a single integer — the smallest amount of time the editorial takes, if Monocarp and Polycarp can choose which kk of nn problems to conduct an editorial for and how to split them among themselves.

输入输出样例

  • 输入#1

    6
    5 4
    1 10 1 1 1
    5 3
    1 20 5 15 3
    5 3
    1 20 3 15 5
    10 6
    10 8 20 14 3 8 6 4 16 11
    10 5
    9 9 2 13 15 19 4 9 13 12
    1 1
    1

    输出#1

    2
    6
    5
    21
    18
    1
首页