#C10065. Maximum Buildings Visited

    ID: 39229 Type: Default 1000ms 256MiB

Maximum Buildings Visited

Maximum Buildings Visited

Given a sequence of n buildings, where each building has a specific height, you are to determine the maximum number of buildings that can be visited starting from any one building. Two buildings are considered "visitable" from one another if the absolute difference in their heights does not exceed a given value k. Formally, for buildings with heights \( h_i \) and \( h_j \), they can be visited together if and only if

[ |h_i - h_j| \leq k ]

Your task is to choose a starting building such that the total number of buildings (including the starting one) meeting the condition is maximized.

Note: You must read the input from standard input (stdin) and output the result to standard output (stdout).

inputFormat

The first line of input consists of two integers n and k, where n (\(1 \leq n \leq 10^5\)) represents the number of buildings and k (\(0 \leq k \leq 10^9\)) is the maximum allowed height difference.

The second line contains n space-separated integers representing the heights of the buildings.

outputFormat

Output a single integer: the maximum number of buildings that can be visited from an optimally chosen starting building.

## sample
5 2
1 3 4 7 6
3