#C9276. Minimum Number of Batches
Minimum Number of Batches
Minimum Number of Batches
You are given T test cases. For each test case, you are provided with two integers: N and C, where N is the number of widgets and C is the maximum capacity of a batch. Then, you are given N positive integers denoting the weights of the widgets. Your task is to determine the minimum number of batches required to pack all the widgets without exceeding the capacity in any batch.
In each batch, widgets are packed using a greedy strategy: first, sort the widgets in descending order by weight. Then, repeatedly select the heaviest widget that can fit into the current batch without exceeding the capacity. Formally, if the remaining capacity of the batch is R, you can add a widget of weight w if and only if $$w \le R$$. Once no more widgets can be added to the current batch, you start a new batch. Continue this process until all widgets are packed.
Note: Although this problem resembles the bin packing problem (which is NP-hard), you are required to implement the procedure as described using the greedy strategy.
inputFormat
The input is read from standard input (stdin) and has the following format:
T N1 C1 w1,1 w1,2 ... w1,N1 N2 C2 w2,1 w2,2 ... w2,N2 ... NT CT wT,1 wT,2 ... wT,NT
Where T is the number of test cases. For each test case, the first line contains two integers: N (the number of widgets) and C (the maximum batch capacity). The second line contains N space-separated integers representing the weights of the widgets.
outputFormat
For each test case, output a single integer on a new line, which is the minimum number of batches required to pack all the widgets.
## sample3
5 10
2 3 8 5 1
4 15
6 7 8 9
6 20
10 10 10 10 10 10
2
2
3
</p>