#P3512. Steady Flight

    ID: 16766 Type: Default 1000ms 256MiB

Steady Flight

Steady Flight

In the Byteotian Training Centre, pilots are assessed based on their ability to maintain a steady flight path. The simulator records the yoke's position at every moment during the flight. Given a tolerance level \(k\), a segment of flight (i.e. a contiguous subarray of measurements) is considered acceptable if the difference between the maximum and minimum yoke positions in that segment is at most \(k\), that is, if

\[ \max_{i \leq j \leq r} a_j - \min_{i \leq j \leq r} a_j \leq k, \]

Your task is to determine the length of the longest contiguous segment where this condition holds.

Input Specification: The input contains an integer \(n\) representing the number of measurements, an integer \(k\) for the tolerance level, followed by a sequence of \(n\) integers representing the yoke's position measurements.

Output Specification: Output a single integer, the length of the longest segment in which the difference between the maximum and minimum measurement does not exceed \(k\).

inputFormat

The first line contains two integers (n) and (k) (where (1 \leq n \leq 10^5) and (0 \leq k \leq 10^9)). The second line contains (n) integers (a_1, a_2, \dots, a_n) ((0 \leq a_i \leq 10^9)) representing the yoke positions.

outputFormat

Output a single integer representing the maximum length of a contiguous segment such that the difference between the maximum and minimum values in that segment is at most (k).

sample

5 3
1 3 6 4 2
3

</p>