Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/eng-uzun-qism

Longest segment

Medium 2000 ms 128 MB 53%
Share

A positive integer $n$, an array $a$ of $n$ positive integers and a positive integer $S$ are given. Find the length of the longest contiguous segment of the array (consecutive elements) whose sum does not exceed $S$. If there is no such segment (every element is greater than $S$), print $0$.

The longest contiguous segment of the array with sum at most S

Input

The first line contains two positive integers: $n$ and $S$. The second line contains $n$ positive integers $a_{i}$ separated by spaces.

Output

One integer — the length of the longest segment, or $0$.

Note

$1 \le n \le 2 * 10^{5}$
$1 \le a_{i} \le 10^{9}$
$1 \le S \le 10^{15}$

Examples

Input #1
5 7
2 1 3 4 1
Output #1
3
Input #2
3 1
5 6 7
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.