#P3512. [POI 2010] PIL-Pilots

[POI 2010] PIL-Pilots

Description

In the Byteotian Training Centre, the pilots prepare for missions requiring extraordinary precision and control. One measure of a pilot's capability is the duration he is able to fly along a desired route without deviating too much - simply put, whether he can fly steadily. This is not an easy task, as the simulator is so sensitive that it registers even a slightest move of the yoke¹. At each moment the simulator stores a single parameter describing the yoke's position. Before each training session a certain tolerance level tt is set. The pilots' task then is to fly as long as they can in such a way that all the yoke's position measured during the flight differ by at most tt. In other words, a fragment of the flight starting at time ii and ending at time jj is within tolerance level tt if the position measurements, starting with ii-th and ending with jj-th, form such a sequence ai,,aja_i, \dots, a_j that for all elements ak,ala_k, a_l of this sequence, the inequality akalt|a_k - a_l| \le t holds.

Your task is to write a program that, given a number tt and the sequence of yoke's position measurements, determines the length of the longest fragment of the flight that is within the tolerance level tt.

  1. Flight control device

Input Format

In the first line of the standard input two integers are given, tt and nn (0t20000000000 \le t \le 2\,000\,000\,000, 1n30000001 \le n \le 3\,000\,000), separated by a single space, denoting the tolerance level and the number of yoke's position measurements taken. The second line gives those measurements, separated by single spaces. Each measurement is an integer from the interval from 11 to 20000000002\,000\,000\,000.

Output Format

Your program should print a single integer to the standard output: the maximum length of a fragment of the flight that is within the given tolerance level.

3 9
5 1 3 5 8 6 6 9 10
4

Hint

Explanation of the example:

There are two longest fragments, both of length 4: 5,8,6,65, 8, 6, 6 and 8,6,6,98, 6, 6, 9.

Task Author: Piotr Chrząstowski.