#C1599. Minimum Boxes Packing
Minimum Boxes Packing
Minimum Boxes Packing
You are given n items with specific weights and an unlimited supply of boxes, each having a maximum weight capacity C. 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 C.
To solve this problem, a greedy strategy is employed. First, sort the items in descending order by weight. Then, for each item, place it into the first box that has enough remaining capacity. If no such box exists, a new box is opened for the item.
This approach is efficient under the problem constraints. For example, if you have 5 items with weights [2, 4, 8, 2, 6] and each box can carry a maximum of 10, the minimum number of boxes required is 3.
inputFormat
The input is read from standard input and consists of three lines:
- The first line contains an integer n, representing the number of items.
- The second line contains n space-separated integers, representing the weights of the items.
- The third line contains an integer C, the maximum weight capacity of each box.
outputFormat
The output is a single integer printed to standard output, representing the minimum number of boxes required to pack all items.
## sample5
2 4 8 2 6
10
3
</p>