#K73352. Maximum Buildings Visited

    ID: 33956 Type: Default 1000ms 256MiB

Maximum Buildings Visited

Maximum Buildings Visited

You are given an integer n representing the number of buildings, an integer d and a sequence of n integers h1, h2, ..., hn representing the heights of the buildings. Starting from any building, you can travel to any other unvisited building j if the absolute difference in height satisfies $$|h_i - h_j| \le d.$$ Your task is to determine the maximum number of different buildings you can visit by moving from one building to another under the above condition. Note that each building can be visited at most once.

inputFormat

The input is read from standard input. The first line contains two integers n and d separated by a space. The second line contains n integers representing the heights of the buildings, separated by spaces.

Example:

6 2
3 4 2 1 5 6

outputFormat

Print a single integer representing the maximum number of buildings that can be visited.

Example Output:

6
## sample
6 2
3 4 2 1 5 6
6