#K9201. Maximize Total Productivity
Maximize Total Productivity
Maximize Total Productivity
You are given T test cases. For each test case, you are provided with:
- An integer K representing the number of teams.
- An integer X representing the number of teams to select.
- A list of K integers representing the productivity of each team.
Your task is to choose exactly X teams so that the total productivity is maximized. In other words, if you sort the productivity values in non-increasing order as \(a_1 \ge a_2 \ge \cdots \ge a_K\), then the answer is given by:
$$ \text{Maximum Productivity} = \sum_{i=1}^{X} a_i $$Print the maximum total productivity for each test case.
inputFormat
The first line contains an integer T
, the number of test cases.
For each test case:
- The first line contains two space-separated integers
K
andX
. - The second line contains
K
space-separated integers representing the productivity values of the teams.
outputFormat
For each test case, output a single line with one integer, the maximum total productivity achievable by selecting X
teams.
4
3 2
10 20 30
4 2
40 10 20 30
5 3
10 15 20 25 30
3 3
10 20 30
50
70
75
60
</p>