#K55877. Maximum Consecutive Books

    ID: 30073 Type: Default 1000ms 256MiB

Maximum Consecutive Books

Maximum Consecutive Books

Jane loves reading, but she has a limit on the total number of pages she is willing to read in one continuous stretch. Given a sequence of books, each with a certain number of pages, your task is to determine the maximum number of consecutive books Jane can read without exceeding her page limit \( L \).

More formally, you are given an integer \( N \) representing the number of books and an array \( pages \) of length \( N \) where \( pages[i] \) denotes the number of pages in the \( i^\text{th} \) book. Find the maximum integer \( k \) such that there exists an interval \( [i, i+k-1] \) for which \[ \sum_{j=i}^{i+k-1} pages[j] \leq L \] This problem can be efficiently solved using the sliding window technique.

inputFormat

The first line of input contains an integer \( T \) representing the number of test cases. Each test case consists of two lines:

  • The first line contains two integers \( N \) and \( L \): the number of books and the page limit respectively.
  • The second line contains \( N \) space-separated integers representing the number of pages in each book.

outputFormat

For each test case, output a single line with one integer: the maximum number of consecutive books that can be read without exceeding the page limit \( L \).

## sample
2
5 10
1 2 3 4 5
6 15
4 3 2 1 5 6
4

5

</p>