#K69012. Sum of Top K Scores

    ID: 32992 Type: Default 1000ms 256MiB

Sum of Top K Scores

Sum of Top K Scores

You are given several test cases. In each test case, you are provided with an integer N representing the number of scores, an integer K representing the number of top scores to sum, and a list of N integer scores. Your task is to compute the sum of the highest K scores for each test case.

More formally, for each test case, if the scores are given as \(a_1,a_2,\dots,a_N\), you need to find the sum of the largest \(K\) numbers, i.e.,

[ \text{result} = \sum_{i=1}^{K} b_i \quad \text{where } b_1 \ge b_2 \ge \dots \ge b_N \text{ is the sorted order of the scores.} ]

Print the result for each test case on a new line.

inputFormat

The input is given via standard input and has the following format:

T
N1 K1
score[1] score[2] ... score[N1]
N2 K2
score[1] score[2] ... score[N2]
...
NT KT
score[1] score[2] ... score[NT]

Where T is the number of test cases. For each test case, the first line of the test case contains two integers: N and K. The following line contains N integers representing the scores.

outputFormat

For each test case, output the sum of the top K scores on a separate line.

## sample
3
5 3
10 20 30 40 50
6 4
100 200 50 300 150 400
4 2
5 25 15 10
120

1050 40

</p>