#C5458. Minimum Boxes to Reach Target Candies

    ID: 49109 Type: Default 1000ms 256MiB

Minimum Boxes to Reach Target Candies

Minimum Boxes to Reach Target Candies

You are given several test cases. In each test case, there are N boxes where the i-th box contains a certain number of candies given by a_i.

Your task is to determine the minimum number of boxes that must be chosen such that the total number of candies is at least M. If it is impossible to obtain at least M candies by selecting all the available boxes, output -1.

The mathematical condition to satisfy is:

\[ \sum_{i=1}^{k} a_i \ge M \]

where k is the number of boxes used. The boxes may be selected in any order; note that a greedy approach of choosing boxes with the largest number of candies first works optimally.

inputFormat

The input is read from standard input (stdin). The first line contains an integer T, the number of test cases. Each test case is described as follows:

  • The first line contains two integers N and M, where N is the number of boxes and M is the target number of candies.
  • The second line contains N space-separated integers, where the i-th integer represents the number of candies in the i-th box.

outputFormat

For each test case, output a single line to standard output (stdout) containing a single integer: the minimum number of boxes required to have a total of at least M candies, or -1 if it is impossible.

## sample
3
5 9
1 2 3 4 5
4 10
1 1 1 1
3 7
10 20 30
2

-1 1

</p>