#C5532. Maximum Non-Adjacent Billboards

    ID: 49192 Type: Default 1000ms 256MiB

Maximum Non-Adjacent Billboards

Maximum Non-Adjacent Billboards

In this problem, you are given a sequence of buildings along a street. Each building has a height given by an integer. You are also provided an integer (H) which represents the minimum required difference between the height of a building and the height of its billboard. A billboard can only be placed on a building if it is at least (H) units shorter than the building; however, according to the strategy used, the actual billboard height is not computed and the (H) value is used only as an input parameter. In addition, no two adjacent billboards can be placed on buildings of the same height. Your task is to calculate the maximum number of billboards that can be placed while following these conditions.

More formally, if the list of building heights is (a_1, a_2, \dots, a_N), you may place a billboard on the first building. For each subsequent building (a_i) ((2 \le i \le N)), you can only place a billboard if (a_i \neq a_{j}) where (a_{j}) is the height of the building on which the previous billboard was placed. Note that although (H) is provided to represent the condition that the billboard is at least (H) units shorter than its building, the placement decision is based solely on the non-adjacent similar height constraint.

inputFormat

The first line contains two integers (N) and (H): the number of buildings and the required height difference (in units) respectively. The second line contains (N) integers (a_1, a_2, \dots, a_N) representing the heights of the buildings. All input values are read from standard input (stdin).

outputFormat

Output a single integer representing the maximum number of billboards that can be placed, printed to standard output (stdout).## sample

6 2
3 5 1 4 8 2
6