#K84282. Longest Subarray with Sum ≤ K

    ID: 36385 Type: Default 1000ms 256MiB

Longest Subarray with Sum ≤ K

Longest Subarray with Sum ≤ K

You are given an array A of N integers and an integer K. Your task is to find the length of the longest contiguous subarray whose sum is less than or equal to K.

Formally, you need to find the maximum integer L such that there exists an index i with \[ \sum_{j=i}^{i+L-1} A_j \leq K \] If no such subarray exists, output 0.

Input and Output

The input is read from standard input and the output should be written to standard output.

inputFormat

The first line contains two integers N and K separated by a space. The second line contains N integers representing the array A.

outputFormat

Print a single integer denoting the length of the longest contiguous subarray whose sum is less than or equal to K. If no valid subarray exists, print 0.## sample

5 10
1 2 3 4 5
4

</p>