#K56692. Maximum Happiness Sum

    ID: 30255 Type: Default 1000ms 256MiB

Maximum Happiness Sum

Maximum Happiness Sum

You are given T test cases. For each test case, you are provided with an integer N (the number of houses), an integer B (the number of houses to select), and an array H of N integers representing the happiness levels of each house.

Your task is to choose exactly B houses such that the sum of their happiness values is maximized. Mathematically, if you sort the given array in descending order and denote the sorted elements as \(H_{(1)}, H_{(2)}, \dots, H_{(N)}\), then the answer for the test case is:

\[ \text{Answer} = \sum_{i=1}^{B} H_{(i)} \]

Print the maximum possible sum for each test case on a new line.

inputFormat

The first line contains a single integer T, the number of test cases.
For each test case:

  • The first line contains two integers N and B, where N is the number of houses and B is the number of houses to select.
  • The second line contains N space-separated integers representing the array H of happiness levels.

outputFormat

For each test case, print a single integer - the maximum possible sum of happiness values by selecting exactly B houses. Each answer should be printed on a new line.

## sample
2
5 2
1 2 3 4 5
7 3
5 8 6 3 2 6 7
9

21

</p>