Bombardment

시간 제한7초메모리 제한1024 MB

요약
남은 점을 가장 많이 포함하는 길이 2R 구간을 반복해 고르되, 동률이면 왼쪽 끝이 가장 작은 구간을 택하고 그 중심들을 순서대로 출력한다.
난이도

보통10점 중 7점

유형
그리디, 슬라이딩 윈도우, 구현, 정렬
정답자
아직 제출이 없습니다

문제

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 \[X−R,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 (1≤N≤5×105)1 \leq N \leq 5 \times 10^5) and RR (1≤R≤1081 \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 40⋅R40 \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.

예제4

  1. 예제 1

    입력
    7 1
    1 2 3 3 4 4 5
    
    예상 출력
    3
    3 0 4
    
  2. 예제 2

    입력
    6 1
    5 -2 5 0 1 2
    
    예상 출력
    3
    1 4 -3
    
  3. 예제 3

    입력
    6 2
    5 -2 5 0 1 2
    
    예상 출력
    2
    0 3
    
  4. 예제 4

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