#K10796. Max Consecutive Bands

    ID: 23326 Type: Default 1000ms 256MiB

Max Consecutive Bands

Max Consecutive Bands

You are given a list of performance times for n bands and a maximum allowed difference d between the performance times of two consecutive bands. Your task is to determine the maximum number of bands that can be scheduled consecutively such that the difference between the performance times of every two consecutive bands does not exceed d.

To solve the problem, you should first sort the performance times in non-decreasing order. Then, traverse the sorted list to count the longest sequence where the difference between each pair of adjacent times is less than or equal to d.
Mathematically, if the sorted times are \(a_1, a_2, \dots, a_n\), you need to find the maximum length \(k\) such that for every \(i = 1, 2, \dots, k-1\) the condition

\[ a_{i+1} - a_i \leq d \]

holds, where \(d\) is given.

inputFormat

The input is read from standard input and consists of two lines:

  • The first line contains two integers n and d: the number of bands and the maximum allowed difference between consecutive performance times.
  • The second line contains n space-separated integers representing the performance times of the bands.

outputFormat

Output a single integer to standard output: the maximum number of consecutive bands that can be scheduled, according to the given condition.

## sample
5 3
30 28 25 27 29
5

</p>