#C5142. Maximum Gift Sum
Maximum Gift Sum
Maximum Gift Sum
You are given t test cases. For each test case, you are provided an integer N which represents the number of gifts available, an integer K which indicates the number of gifts to select, and a list of N integers representing the values of the gifts. Your task is to select K gifts such that their sum is maximized. In other words, you need to choose the K largest numbers from the list.
The mathematical formulation for a single test case is as follows:
where \(a_1, a_2, \dots, a_K\) are the K largest elements extracted from the gift list.
Print the result for each test case on a separate line.
inputFormat
The input is read from stdin and has the following format:
t N1 K1 a11 a12 ... a1N1 N2 K2 a21 a22 ... a2N2 ...
Here, the first line contains an integer t, the number of test cases. For each test case, the first line contains two integers N and K. The next line contains N space-separated integers representing the gift values.
outputFormat
For each test case, output a single line containing the maximum sum obtainable by selecting K gifts.
## sample2
5 3
1 2 3 4 5
4 2
-1 -2 -3 -4
12
-3
</p>