Monster Tower
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

To be The Elden Lord, The Tarnished will face many challenges. Here comes one.
There is a monster tower of height n, the strength of the monster on the i-th floor is a_i. The initial strength of The Tarnished is x.
For any moment, The Tarnished can choose some monster not stronger than him from the lowest k floors, and kill it. After The Tarnished kills the monster on the i-th floor, his strength increases by a_i, and the i-th floor will disappear. So all floors higher than the i-th floor will fall, the original -th floor become the i-th floor, -th becomes -th, and so on.
Now, the problem is what is the minimum x to kill all monsters in this tower.

输入描述:

The first line contains a single integer  --- the number of test cases.
The first line of each test case contains two integers and --- the height of the tower and the highest floor that The Tarnished can reach respectively.
The second line of each test case contains n integers --- the strength of each monster.
It is guaranteed that over all test cases.

输出描述:

For each test case, output a single integer --- the minimum x to kill all monsters.
示例1

输入

复制
2
3 2
1 10 5
3 1
1 10 5

输出

复制
4
9

说明

In the first test case, The Tarnished kills the monster on the first floor, so his strength becomes 5, and the third floor becomes the second floor so The Tarnished can reach it and kill the monster. After that, his strength becomes 10 and can kill the last one.