P8656 [Lanqiao Cup 2017 National B] Matchmaking
Description
Xiao Ming likes to find other people to play Go online on a Go website. All registered users on this website have a rating score, which represents their Go skill level.
Xiao Ming found that when matching opponents, the website’s automatic matchmaking system only matches two users whose rating difference is exactly $K$. If their difference is less than or greater than $K$, the system will not match them.
Now Xiao Ming knows that the website has a total of $N$ users, and their ratings are $A_1, A_2, \cdots A_N$.
Xiao Ming wants to know: at most how many users can be online at the same time looking for opponents, but the system still cannot match even a single game (i.e., for any two users, their rating difference is not equal to $K$)?
Input Format
The first line contains two integers $N$ and $K$.
The second line contains $N$ integers $A_1, A_2, \cdots, A_N$.
Output Format
Output one integer, representing the answer.
Explanation/Hint
For $30\%$ of the testdata, $1 \le N \le 10$.
For $100\%$ of the testdata, $1 \le N \le 10^5$, $0 \le K, A_i \le 10^5$.
Time limit: 1 second, 256 MB. Lanqiao Cup, 2017 8th National Finals.
Translated by ChatGPT 5