#C5964. Minimum Number of Shelves

    ID: 49671 Type: Default 1000ms 256MiB

Minimum Number of Shelves

Minimum Number of Shelves

You are given a sequence of books with specific widths and a shelf that can hold books with a maximum total width W. The books must be placed on the shelves in the given order. A new shelf is started when the current book does not fit in the current shelf. Your task is to calculate the minimum number of shelves required to store all the books.

Formally, let \(n\) be the number of books and \(w_1, w_2, \dots, w_n\) be the widths of the books. Each shelf can accommodate books with a total width of at most \(W\). Determine the minimum number of shelves needed if you place the books sequentially on the shelves.

Input/Output Format: The program reads input from standard input and prints the result to standard output.

inputFormat

The input consists of two lines:

  • The first line contains two integers \(n\) and \(W\) where \(n\) is the number of books and \(W\) is the maximum width capacity of each shelf.</p>
  • The second line contains \(n\) integers representing the widths of the books in the given order.

outputFormat

Output a single integer: the minimum number of shelves required to hold all books.

## sample
5 10
6 3 5 2 7
3