#K55547. Longest Subarray with Sum at Most S
Longest Subarray with Sum at Most S
Longest Subarray with Sum at Most S
Given an array of integers, your task is to find the length of the longest contiguous subarray such that the sum of its elements is at most a given value \(S\). This problem can be efficiently solved using a sliding window technique. For each test case, you are required to read the input from standard input (stdin) and output the result to standard output (stdout).
For instance, for the array [1, 2, 3, 4, 5] with \(S = 10\), the longest valid subarray is [1, 2, 3, 4] which has length 4.
inputFormat
The input begins with an integer \(T\) indicating the number of test cases. Each test case consists of two lines:
- The first line contains two space-separated integers \(n\) (the length of the array) and \(S\) (the maximum allowed sum).
- The second line contains \(n\) space-separated integers representing the elements of the array.
outputFormat
For each test case, output a single integer—the length of the longest contiguous subarray whose sum of elements is less than or equal to \(S\). Each result should be printed on a new line.
## sample2
5 10
1 2 3 4 5
4 8
4 2 2 2
4
3
</p>