#K75982. Maximum Consecutive Books

    ID: 34540 Type: Default 1000ms 256MiB

Maximum Consecutive Books

Maximum Consecutive Books

You are given N books with the number of pages in each book represented by an array P. You want to read as many consecutive books as possible without exceeding a given total page limit M. In other words, you need to find the maximum length of a contiguous subarray such that (\sum_{i=l}^{r} P_i \le M). This problem requires an efficient sliding window technique to ensure that the solution works even for large inputs.

inputFormat

The input is provided via standard input (stdin). The first line contains two integers N and M, where N is the number of books and M is the maximum total pages that can be read. The second line contains N space-separated integers representing the pages in each book (the array P).

outputFormat

Output a single integer: the maximum number of consecutive books that can be read without the sum of their pages exceeding M. The output should be printed to standard output (stdout).## sample

5 100
20 30 50 10 40
3