Bombardment
Time limit7sMemory limit1024 MB
Simulate the greedy strategy that repeatedly picks the integer center covering the most remaining points, taking the smallest center on ties, and print the centers in order.
- Level
Medium7 of 10
- Topics
- Greedy, Sliding window, Sorting, Array
- Solved
- No attempts yet
Problem
The goal of the game Bombardment is to destroy a set of points by bombarding them. The theme is not decided yet, and the core mechanic is a bombardment.
The points lie on the real number line, and each point is given only by its -coordinate. A bombardment is centered at an integer and destroys every point in the interval .
Most testers use a greedy strategy. Each bombardment is chosen to destroy the largest number of points at that moment. Because of this, players sometimes use more bombardments than the minimum possible. Write a program that simulates this strategy.
The process is as follows. While points remain, choose the center of a bombardment that destroys the maximum number of remaining points. If several centers give the maximum, choose the smallest one.
Input
The first line contains two integers () and (). The next line contains integers, the -coordinates of the points, each in the range . Several points may share the same -coordinate. The difference between the maximum and minimum -coordinate is at most .
Output
On the first line, print the number of bombardments . On the second line, print the -coordinates of the bombardments in the order they were performed.