Power Outage

Time limit1sMemory limit256 MB

Summary
Decide which lamps run in blackouts to maximize the road length lit both normally and during blackouts.
Level

Medium6 of 10

Topics
Intervals, Sorting, Greedy
Solved
No attempts yet

Problem

The city of OJ put up NN street lamps along a straight tree lined road. The position of each lamp is an integer coordinate between −1,000,000,000-1{,}000{,}000{,}000 and 1,000,000,0001{,}000{,}000{,}000, measured from the subway station. Every lamp lights up each point within distance LL of itself. For example, a lamp at coordinate 55 with reach 22 lights up the coordinates from 33 to 77.

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 NN 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 NN and the reach LL of a lamp, separated by a space.

The second line contains the coordinates of the NN lamps, separated by spaces. The coordinates are not guaranteed to be sorted, and two or more lamps can sit at the same coordinate.

  • 1≤N≤150,0001 \le N \le 150{,}000
  • 1≤L≤1,000,000,0001 \le L \le 1{,}000{,}000{,}000
  • Each coordinate is an integer between −1,000,000,000-1{,}000{,}000{,}000 and 1,000,000,0001{,}000{,}000{,}000.

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 −2-2 and the lamp at coordinate 33 to emergency mode.

Examples3

  1. Example 1

    Input
    6 3
    -6 -2 1 3 8 15
    
    Expected output
    9
    
  2. Example 2

    Input
    5 2
    0 4 8 12 16
    
    Expected output
    0
    
  3. Example 3

    Input
    3 5
    0 1 2
    
    Expected output
    10