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

~/algor $ cat problems/ikki-korsatkich-farqi-k-qism

Longest segment with spread at most k

Hard 2000 ms 128 MB 95%
Share

An array $a$ of $n$ integers and an integer $k$ are given. Find the longest segment of consecutive elements in which the difference between the largest and the smallest element does not exceed $k$. Print the length of this segment.

Array values as columns: the longest window where the difference between the largest and the smallest is at most k is highlighted

Input

The first line contains two integers: $n$ and $k$.
The second line contains $n$ integers $a_{i}$.

Output

One positive integer — the largest length.

Note

$1 \le n \le 10^{5}$
$0 \le k \le 10^{9}$
$0 \le a_{i} \le 10^{9}$

Examples

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

Sign in to submit a solution

Signing up is free and takes a minute.