Books

Practice this coding question on Coding Gurukul.

Problem statement

Valera has t minutes available and n books arranged in order. Book i takes a_i minutes to finish. He may start at any book, then read consecutive books in their original order. He cannot skip books or begin one unless enough time remains to finish it. Determine the largest number of complete books he can read. If none fits, the answer is 0.

Input format

The first line contains n and t. The second line contains n integers a_1, a_2, ..., a_n, the reading times in minutes.

Output format

Print the maximum number of consecutive books whose total reading time is at most t.

Constraints

1 ≤ n ≤ 100000 1 ≤ t ≤ 1000000000 1 ≤ a_i ≤ 10000 Original time limit: 2 seconds Original memory limit: 256 MB

Sample input

4 5
3 1 2 1

Sample output

3

Sign in to run or submit a solution in C++, Java or Python.