#K49482. Maximum Books on Shelf

    ID: 28652 Type: Default 1000ms 256MiB

Maximum Books on Shelf

Maximum Books on Shelf

You are given several test cases. In each test case, a shelf has a maximum capacity (C) and there are (N) books with given thicknesses (t_1, t_2, \dots, t_N). Your task is to determine the maximum number of books that can be placed on the shelf without exceeding its capacity. To solve the problem, you may sort the books by their thickness and then pick books greedily until the total thickness exceeds (C). In other words, find the maximum (k) such that (\sum_{i=1}^{k} t_i \le C).

inputFormat

The input is read from standard input (stdin). The first line contains an integer (T) representing the number of test cases. Each test case consists of two lines. The first line of a test case contains two integers (N) and (C), denoting the number of books and the shelf capacity respectively. The second line contains (N) space-separated integers representing the thicknesses of the books.

outputFormat

For each test case, output a single integer representing the maximum number of books that can be placed on the shelf, such that the sum of their thicknesses does not exceed (C). The results for all test cases should be printed on one line separated by a space, and the output is written to standard output (stdout).## sample

2
5 10
2 3 4 5 1
4 7
4 3 5 1
4 2