#P8656. Maximum Online Users Without Matching Pair

    ID: 21822 Type: Default 1000ms 256MiB

Maximum Online Users Without Matching Pair

Maximum Online Users Without Matching Pair

On a Go (weiqi) website, every registered user has a rating score representing their level. The website uses an automatic pairing system that only matches two users if the absolute difference of their scores is exactly \(K\). If the difference is less or greater than \(K\), the system will not match them.

There are \(N\) users with scores \(A_1, A_2, \ldots, A_N\). Now, Xiao Ming wonders: What is the maximum number of users that can be online simultaneously such that no pair of online users has a score difference equal to \(K\) (i.e. the system cannot form any match)?

Note: When \(K = 0\), any two users with the same score would be matched; hence, at most one user per distinct score can be online.

inputFormat

The first line contains two integers \(N\) and \(K\) (where \(N\) is the number of users and \(K\) is the required absolute difference for pairing).

The second line contains \(N\) integers \(A_1, A_2, \ldots, A_N\) separated by spaces, representing the scores of the users.

outputFormat

Output a single integer: the maximum number of users that can be online such that no two have an absolute score difference equal to \(K\).

sample

5 2
1 3 4 6 8
3