#K13926. Longest Contiguous Subarray Under Sum Constraint
Longest Contiguous Subarray Under Sum Constraint
Longest Contiguous Subarray Under Sum Constraint
Given an array of N integers and a target sum S, your task is to find the length of the longest contiguous subarray whose sum is less than or equal to S. More formally, you are to find the maximum length L such that for some indices i and j (with \(i \le j\)) the sum \(\sum_{k=i}^{j} a_k \le S\). Use an efficient algorithm to handle large inputs.
Note: The input is read from standard input and the output should be printed to standard output.
inputFormat
The first line of input contains two space-separated integers N and S, where N is the number of elements in the array and S is the maximum sum allowed. The second line contains N space-separated integers representing the array elements.
Input Format:
N S a1 a2 a3 ... aN
outputFormat
Output a single integer representing the length of the longest contiguous subarray whose sum is less than or equal to S.
## sample5 10
1 2 3 4 5
4