#C887. Minimum Shelves Needed
Minimum Shelves Needed
Minimum Shelves Needed
You are given a row of n books, each with a given thickness. Your task is to determine the minimum number of shelves required so that the books can be arranged in contiguous groups, where the sum of the thicknesses in each group does not exceed a given maximum capacity \(T\). This problem is equivalent to partitioning the array \(a = [a_1, a_2, \dots, a_n]\) into the fewest number of contiguous subarrays such that for every subarray \(S\), \(\sum_{x \in S} x \le T\).
Example:
- For \(n = 5\), thicknesses \([2, 1, 3, 4, 5]\) and \(T = 5\), one optimal grouping is \([2, 1], [3], [4], [5]\), so the answer is 4.
inputFormat
The input begins with an integer \(T\) representing the number of test cases. Each test case consists of two lines:
- The first line contains two integers \(n\) (the number of books) and \(max_thickness\) (the maximum allowable thickness per shelf).
- The second line contains \(n\) space-separated integers indicating the thicknesses of the books.
outputFormat
For each test case, output a single line containing the minimum number of shelves required to store the books under the given constraints.
## sample1
5 5
2 1 3 4 5
4
</p>