#C4773. Minimum Shelves Problem
Minimum Shelves Problem
Minimum Shelves Problem
You are given a list of books represented by their heights and a shelf height limit \(H\). Your task is to determine the minimum number of shelves required to store all the books in the given order. For each shelf, the cumulative height of the books must not exceed \(H\), i.e., for every shelf containing books with heights \(h_i\), the condition \(\sum h_i \leq H\) must hold.
The books must be arranged in the given order. Use a greedy strategy: keep adding book heights to the current shelf until adding the next book would exceed \(H\); then start a new shelf.
inputFormat
The input is read from standard input and has the following format:
n H h1 h2 ... hn
Here, \(n\) is the number of books and \(H\) is the shelf height limit. The second line contains \(n\) integers representing the heights of the books in the given order.
outputFormat
Output a single integer indicating the minimum number of shelves required.
## sample6 10
5 8 7 3 5 2
4