Alice and Bob are playing a game on an array of integers. The game lasts for rounds.
Each round goes like this:
Alice picks an integer where
Bob either erases the first elements from the array or keeps only these elements in the array erasing the rest of them.
Now, Alice tries to minimize the sum of the elements of the final array and Bob tries to maximize it. If they both play optimally, what will be the sum of the elements of the final array?
Note that, the array may even become empty during the game and the sum of elements of an empty array is 0.
The first line of the input will contain a single integer denoting the number of test cases. The description of test cases follows:
Each testcase will start with a line containing two positive integers , denoting the number of elements of the array and the number of rounds the game is played respectively. Next line will contain space separated integers .
Sum of over all testcases does not exceed
Sum of over all testcases does not exceed
Sum of over all testcases does not exceed
For each testcase, output in a line, the sum of the elements of the array after the game ends. See sample for details.
Input | Output |
---|---|
3 5 1 1 2 3 4 5 5 2 1 2 3 4 5 5 3 1 2 3 4 5 | 9 5 5 |
In the first testcase,
1st round:
Alice picks .
Bob erases the first elements and the remaining elements are: .
The sum of the elements of the array after the game ends .
In the third testcase,
1st round:
Alice picks .
Bob erases the first elements and the remaining elements are: .
2nd round:
Alice picks .
Bob keeps the first elements and erases the rest of them.
The remaining elements are: .
3rd round:
Alice picks .
Bob keeps the first elements and erases the rest of them.
The remaining elements are: .
The sum of the elements of the array after the game ends .