#P8656. [蓝桥杯 2017 国 B] 对局匹配

    ID: 7712 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>动态规划 DP2017蓝桥杯国赛

[蓝桥杯 2017 国 B] 对局匹配

Problem 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 KK. If their difference is less than or greater than KK, the system will not match them.

Now Xiao Ming knows that the website has a total of NN users, and their ratings are A1,A2,ANA_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 KK)?

Input Format

The first line contains two integers NN and KK.

The second line contains NN integers A1,A2,,ANA_1, A_2, \cdots, A_N.

Output Format

Output one integer, representing the answer.

10 0
1 4 2 8 5 7 1 4 2 8
6
10 1
2 1 1 1 1 4 4 3 4 4
8

Hint

For 30%30\% of the testdata, 1N101 \le N \le 10.

For 100%100\% of the testdata, 1N1051 \le N \le 10^5, 0K,Ai1050 \le K, A_i \le 10^5.

Time limit: 1 second, 256 MB. Lanqiao Cup, 2017 8th National Finals.

Translated by ChatGPT 5