公路维修问题

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Problem Description

Due to long-term lack of maintenance, there are nn potholes on Country A’s highway. To repair these nn potholes quickly, Country A decides to impose traffic control on mm segments of the road. For simplicity, assume there is only one highway, and it is straight. Given the positions of the nn 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 n,mn, m (2mn150002 \le m \le n \le 15000).
  • The second line contains the coordinates of the nn 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: 38,1421,2531,40433-8, 14-21, 25-31, 40-43.

Translated by ChatGPT 5

第 25 课:贪心算法

未认领
状态
已结束
题目
21
开始时间
2026-7-7 19:00
截止时间
2026-7-14 19:00
可延期
24 小时