#C1292. Maximum Score by Summing K Largest Elements

    ID: 42400 Type: Default 1000ms 256MiB

Maximum Score by Summing K Largest Elements

Maximum Score by Summing K Largest Elements

You are given an array of integers. For each test case, you need to compute the maximum score by selecting exactly K numbers from the array. The maximum score is defined as the sum of the K largest integers.

Formally, for each test case, you are given two integers N and K followed by an array arr of N integers. Your task is to select exactly K elements from arr such that their sum is maximized. The answer for each test case is the sum of these K selected integers.

Note: All input numbers can be large. Please make sure to use appropriate data types.

inputFormat

The input is given from standard input and begins with an integer T, the number of test cases. Each test case consists of:

  • A line with two integers N and K, where N is the number of elements and K is the number of elements to pick.
  • A line with N space-separated integers representing the array arr.

outputFormat

For each test case, output on a new line the maximum score (i.e. the sum of the K largest elements).

## sample
1
5 3
1 2 3 4 5
12

</p>