#K45227. Maximize Problem Difficulties Sum
Maximize Problem Difficulties Sum
Maximize Problem Difficulties Sum
Anu is participating in a coding marathon that consists of N problems. Each problem has an associated difficulty level represented by an integer. She has K minutes to solve the problems, and each problem takes exactly 1 minute, regardless of its difficulty.
The objective is to maximize the total difficulty level of the problems solved in the given time. Formally, if the difficulties are given by (d_1, d_2, \dots, d_N), you are to choose exactly (K) problems such that the sum (\sum_{i=1}^{K} d_{i}) is maximized.
Note: Since each problem takes a constant time (1 minute), this reduces to selecting the (K) largest values from the list of difficulties.
inputFormat
The first line contains an integer (T) representing the number of test cases. For each test case, the first line contains two integers (N) and (K) where (N) is the number of problems and (K) is the number of minutes available. The second line contains (N) space-separated integers representing the difficulty levels of the problems.
outputFormat
For each test case, output a single integer on a new line representing the maximum sum of difficulties that can be achieved by solving exactly (K) problems.## sample
2
5 3
10 20 30 40 50
4 2
15 5 10 25
120
40
</p>