#K12886. Maximum Coins Distribution among Commanders

    ID: 23790 Type: Default 1000ms 256MiB

Maximum Coins Distribution among Commanders

Maximum Coins Distribution among Commanders

You are given a problem where a commander must distribute coins to a set of subordinate commanders. There is a limit \(K\) on the total number of coins available. Each subordinate commander has a coin handling capacity, and the goal is to distribute as many coins as possible without exceeding \(K\) by following a greedy strategy.

For each test case, the first line contains two integers \(N\) (the number of commanders) and \(K\) (the total coin limit). The second line contains \(N\) integers, each representing a commander's coin handling capacity. To solve this problem, you should sort the capacities in descending order and add each capacity to the total distribution. If adding the whole number would exceed \(K\), add only the amount required to reach \(K\).

inputFormat

The input begins with an integer \(T\), the number of test cases. For each test case, the input format is as follows:

  • The first line contains two integers \(N\) and \(K\), where \(N\) is the number of commanders and \(K\) is the coin limit.
  • The second line contains \(N\) space-separated integers representing the coin handling capacities.

outputFormat

For each test case, output a single line with the maximum number of coins that can be distributed without exceeding \(K\).

## sample
2
3 50
10 20 15
4 100
35 40 25 50
45

100

</p>