#C7985. Minimum Number of Boxes
Minimum Number of Boxes
Minimum Number of Boxes
You are given a list of products, each with a given weight, and a weight limit for each box. Your task is to determine the minimum number of boxes required in order to pack all the products such that the total weight in any box does not exceed the limit.
Formally, given a positive integer \(w\) representing the maximum weight allowed per box, an integer \(m\) which denotes the number of products, and a list of \(m\) positive integers representing the weights of each product, compute the minimum number of boxes required to pack all products. Note that each box can contain one or more products as long as the sum of their weights is at most \(w\).
It is guaranteed that all product weights are positive integers and \(w \geq \max{(weights)}\), ensuring that every product can fit in a box on its own.
inputFormat
The input consists of multiple test cases. For each test case:
- The first line contains two integers \(w\) and \(m\), where \(w\) is the maximum weight allowed per box and \(m\) is the number of products.
- The second line contains \(m\) space-separated integers representing the weights of the products.
The input terminates with a test case where both \(w\) and \(m\) are 0, which should not be processed.
outputFormat
For each test case, output a single integer on a new line representing the minimum number of boxes required.
## sample10 6
2 3 5 7 1 4
0 0
3
</p>