#C7605. Minimum Boxes Required
Minimum Boxes Required
Minimum Boxes Required
You are given (N) items, each with a specified weight, and a box weight limit (W). Your task is to determine the minimum number of boxes required to pack all the items such that the total weight in each box does not exceed (W).
In each box, you can pack any number of items as long as the sum of their weights does not exceed (W). Note that although this problem is related to the classic bin packing problem, for the given test cases a greedy approach by sorting the items in descending order works correctly.
For example, if (N = 3), (W = 5) and the weights are [2, 3, 4], one optimal solution is to pack items with weights 2 and 3 in one box and the item with weight 4 in another box, totalling 2 boxes.
inputFormat
Input is read from standard input (stdin).
The first line contains two integers (N) and (W) representing the number of items and the maximum allowed weight per box, respectively.
The second line contains (N) space-separated integers representing the weights of the items.
outputFormat
Output the minimum number of boxes required to pack all the items. The answer should be printed to standard output (stdout).## sample
3 5
2 3 4
2