Power Outage
Time limit1sMemory limit256 MB
Decide which lamps run in blackouts to maximize the road length lit both normally and during blackouts.
Problem
The city of OJ put up street lamps along a straight tree lined road. The position of each lamp is an integer coordinate between and , measured from the subway station. Every lamp lights up each point within distance of itself. For example, a lamp at coordinate with reach lights up the coordinates from to .
Power shortages have made blackouts frequent in OJ. A blackout leaves the road completely dark, which is bad for public safety. The city will switch some of the lamps to emergency mode so that they turn on only during a blackout. A lamp that is not switched stays on normal duty and turns on only in normal times.
Lighting has to stay even in both states so that residents use the road comfortably at any hour. The city wants to maximize the total length of the points that receive light in normal times and during a blackout alike. Write a program that decides which lamps to switch and reports that maximum length.
Input
The first line contains the number of lamps and the reach of a lamp, separated by a space.
The second line contains the coordinates of the lamps, separated by spaces. The coordinates are not guaranteed to be sorted, and two or more lamps can sit at the same coordinate.
- Each coordinate is an integer between and .
Output
Print one integer, the maximum length of the region that receives light in normal times and during a blackout alike.
Hint
In the first example, switch the lamp at coordinate and the lamp at coordinate to emergency mode.