#K84117. Max Boxes on a Shelf
Max Boxes on a Shelf
Max Boxes on a Shelf
You are given a shelf with a maximum capacity \( C \) and a set of \( n \) boxes with specific sizes. Your task is to determine the maximum number of boxes that can be placed on the shelf without exceeding its capacity. You can select the boxes in any order; however, to maximize the count, it is optimal to use the smallest boxes first.
Problem Analysis: To solve the problem, sort the list of box sizes in non-decreasing order. Then, sequentially add the sizes until the cumulative sum would exceed the shelf's capacity. The number of boxes added before exceeding \( C \) is the answer.
The input contains multiple test cases. For each test case, you will be given:
- An integer \( n \) denoting the number of boxes and an integer \( C \) for the capacity of the shelf.
- A list of \( n \) integers representing the sizes of the boxes.
Your program should process all test cases and output the maximum number of boxes that fit for each test case on a separate line.
inputFormat
The first line contains a single integer \( T \) representing the number of test cases.
For each test case, the input is structured as follows:
- A line containing two integers \( n \) and \( C \), where \( n \) is the number of boxes and \( C \) is the capacity of the shelf.
- A line containing \( n \) space-separated integers denoting the sizes of the boxes.
outputFormat
For each test case, output a single integer on its own line representing the maximum number of boxes that can be placed on the shelf without exceeding its capacity.
## sample3
5 10
1 2 3 4 5
4 5
4 3 1 2
6 12
6 5 6 5 7 8
4
2
2
</p>