Street Development
Time limit1sMemory limit2048 MB
Given n robot positions on the street [0, L], find the minimum battery capacity P that lets robots merge all collected information into one robot.
- Level
Medium6 of 10
- Topics
- Binary search, Greedy, Array
- Solved
- No attempts yet
Problem
ICPC street is still an undeveloped area, and a large-scale development plan is scheduled to start soon. Before development begins, remote-controlled robots collect information from important points along the street, one robot per point. The goal is to combine all the collected information into a single robot so that the most efficient development approach can be found.
The street is the interval for a positive integer . The important points are integers on the interval, including both endpoints. That is, and . At the start, each robot stands at one important point and already has that point's information. There is exactly one robot per point, so is also the number of robots. .
- Robots can move left or right freely. Each unit of distance traveled costs 1 unit of battery, in either direction. All robots have the same battery capacity, an integer , and move only in integer units of distance.
- When two or more robots meet at an integer position, they combine each other's information. For example, if a robot holding the information of and meets a robot holding the information of and , both robots then have the information of , , , and .
- Battery is used only for movement. Changing direction and combining information cost no battery.
- After all movements, at least one robot must have the information of all of .

The figure shows an example with and . Robots R1, R2, R3, and R4 start at , , , and . With battery capacity , the following steps can be performed. Robot 1 moves to , and robots 1 and 2 combine their information. Robot 4 moves to , and robots 3 and 4 combine their information. Robot 2 moves 2 units to the right, robot 3 moves 2 units to the left, and they combine their information at position 5. Afterward, robots 2 and 3 have the information of all four points.
Input
The first line contains two positive integers and (, ). The second line contains distinct integers between and in increasing order, which are the initial positions of the robots. The first integer is and the last one is .
Output
Print one line containing a single integer: the minimum battery capacity that lets at least one robot have the information of all important points.