#P2242. 公路维修问题
公路维修问题
Description
Due to long-term lack of maintenance, there are potholes on Country A’s highway. To repair these potholes quickly, Country A decides to impose traffic control on segments of the road. For simplicity, assume there is only one highway, and it is straight. Given the positions of the potholes, compute the minimal total length of road that must be under traffic control.
Input Format
The input consists of two lines.
- The first line contains two positive integers ().
- The second line contains the coordinates of the potholes (each within the 64-bit signed integer range), given in strictly increasing order with no duplicate coordinates.
Output Format
Output a single line: the minimal total length.
18 4
3 4 6 8 14 15 16 17 21 25 26 27 30 31 40 41 42 43
25
Hint
[Sample Explanation]
The controlled segments are: .
Translated by ChatGPT 5
京公网安备 11011102002149号