cswork / OAOpen practice workspace

UberOA #37

Find Maximum Length Subarray

Estimated MediumJudge-ready

Topics (AI-labelled)Binary SearchPrefix & Ranges

Given an array of positive integers and k, find the maximum length L such that every contiguous subarray of length L has a sum strictly less than k. If no positive length works, output 0.

This site has made the standard input and output explicit.

Input

The first line contains n k, and the second line contains n positive integers. 1≤n≤200000, 1≤a[i]≤10⁹, 1≤k≤10¹⁸.

Output

Output one integer, the answer.

Example 1

Input:

4 8
3 1 2 4

Output:

3

Example 2

Input:

1 9
9

Output:

0

Example 3

Input:

3 10
1 1 1

Output:

3

Example notes

Example 1: the two windows of length 3 have sums 6 and 7, both less than 8; length 4 gives 10, which fails, so the answer is 3. Example 2: the only element sums to 9, which is not strictly less, so the answer is 0. Example 3: the whole array sums to 3, less than 10, so the maximum length is 3.

Editorial

Loading solution…