#C10415. Maximum Passengers Selection
Maximum Passengers Selection
Maximum Passengers Selection
You are given a list of stations, each station has a certain number of passengers waiting. The task is to choose exactly K stations such that the total number of passengers collected is maximized. In other words, you need to find a subset S of stations of size K that maximizes the sum:
\(\sum_{i \in S} p_i\)
where \(p_i\) represents the number of passengers at the ith station.
Note: It is guaranteed that K is less than or equal to the number of stations N in each test case.
inputFormat
The first line of input contains an integer T representing the number of test cases.
For each test case, the first line contains two space-separated integers N and K, where N is the number of stations and K is the number of stations you must choose. The second line contains N space-separated integers, where the ith integer denotes the number of passengers at the ith station.
outputFormat
For each test case, output a single line containing one integer: the maximum possible sum of passengers that can be achieved by selecting exactly K stations.
## sample1
5 3
10 20 30 40 50
120
</p>