#P1837F. Editorial for Two
Editorial for Two
Description
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 $n$ problems in the contest. The problems are numbered from $1$ to $n$. The editorial for the $i$-th problem takes $a_i$ minutes. Monocarp and Polycarp are going to conduct an editorial for exactly $k$ of the problems.
The editorial goes as follows. They have a full problemset of $n$ problems before them, in order. They remove $n - k$ problems without changing the order of the remaining $k$ problems. Then, Monocarp takes some prefix of these $k$ 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.
谷歌翻译
Berland校际竞赛刚刚结束。 Monocarp 和 Polycarp 作为评审团将发表社论。不幸的是,时间有限,因为他们必须在闭幕式之前完成。
比赛中出现了 个问题。问题编号从 到 。第 个问题的社论需要 分钟。 Monocarp 和 Polycarp 将针对其中的 个问题进行社论。
社论如下。他们面前摆着一整套按顺序排列的 个问题。他们删除了 问题,但不更改其余 问题的顺序。然后,Monocarp 获取这些 问题的一些前缀(可能是一个空问题或所有问题)。波利卡普 (Polycarp) 采用其中剩余的后缀。之后,他们去不同的房间,并行地针对自己的问题进行社论。因此,社论所花费的时间与两者中较长者所花费的时间一样多。
请帮助 Monocarp 和 Polycarp 选择问题和拆分,以便社论尽早完成。打印社论的持续时间。
Input
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases.
The first line of each testcase contains two integers $n$ and $k$ ($1 \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 $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the time each editorial takes.
The sum of $n$ over all testcases doesn't exceed $3 \cdot 10^5$.
Output
For each testcase, print a single integer — the smallest amount of time the editorial takes, if Monocarp and Polycarp can choose which $k$ of $n$ problems to conduct an editorial for and how to split them among themselves.
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
2
6
5
21
18
1
相关
在下列比赛中: