#K76552. Longest Segment of Books Under Page Limit

    ID: 34667 Type: Default 1000ms 256MiB

Longest Segment of Books Under Page Limit

Longest Segment of Books Under Page Limit

You are given several test cases. For each test case, you have a sequence of books where each book has a number of pages. With a given maximum allowed total page count \(P\), your task is to determine the length of the longest contiguous segment of the books whose total number of pages does not exceed \(P\).

Input Constraints:

  • The first line contains an integer \(t\) representing the number of test cases.
  • For each test case, the first line contains two integers \(N\) and \(P\): \(N\) is the number of books and \(P\) is the maximum allowed page count for a segment.
  • The second line of the test case contains \(N\) integers, where each integer denotes the number of pages in a book.

Output:

For each test case, output a single integer that represents the length of the longest contiguous segment of books such that the sum of their pages is at most \(P\). If no valid segment exists, print 0.

Note: A contiguous segment means the books are consecutive in order.

inputFormat

The input begins with an integer (t) denoting the number of test cases. For each test case, the first line contains two space-separated integers (N) and (P). The next line contains (N) space-separated integers representing the number of pages in each book.

outputFormat

For each test case, output a single line with the length of the longest contiguous segment of books such that the sum of their pages is at most (P).## sample

2
5 10
1 2 3 4 5
4 50
12 15 5 32
4

3

</p>