~/algor $ cat problems/ikki-korsatkich-farqi-k-qism
Longest segment with spread at most k
Hard
2000 ms
128 MB
95%
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.
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