PivotOJ

Bombardment

시간 제한: 7000ms메모리 제한: 1024MB출처: ICPC Rocky Mountain Regional 2023-2024BOJ 30543

문제

You are designing an old-school game you call Bombardment where the goal is to destroy a number of points by bombarding them. You do not yet know the theme of your game, just that the core mechanics should involve a bombardment.

The points to be destroyed are located on the real number line, that is each point is simply an xx-coordinate. A bombardment is an attack that will destroy all points within some fixed distance RR from the center of the bombardment. More specifically, a single bombardment is specified by picking an integer point XX (the center). All points lying in the interval [XR,X+R][X-R, X+R] will be destroyed.

You decide to playtest a basic version of this game before you go through the effort of designing a theme, adding nice graphics, etc. Interestingly, most testers seemed to employ a greedy strategy: each bombardment is chosen to destroy the maximum number of points in that single bombardment. Sometimes, this causes players to use more bombardments than the minimum possible number of bombardments. You want to design a program that will simulate this strategy, this will help you design interesting levels.

That is, your job is to write a program that will simulate the following process. While there are still points remaining, choose a value XX for a bombardment that will destroy the maximum number of remaining points. If there are multiple values XX for the center of such a bombardment, you will choose the least such XX each time.

입력

The first line of input contains two integers NN (1N5×105)1 \leq N \leq 5 \times 10^5) and RR (1R1081 \leq R \leq 10^8). The next line contains NN integers describing the xx-coordinates of the points, each lying in the range [108,108][-10^8, 10^8]. Multiple points may share the same xx-coordinate. You are also guaranteed that the difference between the maximum xx-coordinate and the minimum xx-coordinate is at most 40R40 \cdot R.

출력

The first line of output contains a single integer BB indicating the number of bombardments that were performed. The second line consists of BB integers describing the xx-coordinates of each bombardment in the order they were performed.

예제

예제 1

입력
7 1
1 2 3 3 4 4 5
출력
3
3 0 4

예제 2

입력
6 1
5 -2 5 0 1 2
출력
3
1 4 -3

예제 3

입력
6 2
5 -2 5 0 1 2
출력
2
0 3

예제 4

입력
6 3
5 -2 5 0 1 2
출력
2
2 -5
코드를 제출하려면 로그인하세요.