#P6246. [IOI 2000] 邮局 加强版 加强版
[IOI 2000] 邮局 加强版 加强版
Description
There are villages along a highway. The highway is represented as an integer line, and the position of each village is given by a single integer coordinate. The distance between two positions is the absolute value of the difference of their integer coordinates.
Now we want to build post offices. Post offices will be built in some, but not necessarily all, villages. To build the post offices, we should choose their locations so that the sum of distances from each village to its nearest post office is minimized.
You need to write a program that, given the village positions and the number of post offices, computes the minimum possible total sum of distances from each village to its nearest post office.
Input Format
The first line contains two integers, representing the number of villages and the number of post offices .
The second line contains integers, where the -th integer is the coordinate of the -th village.
Output Format
Output one line with one integer, representing the answer.
5 2
0 1 2 3 4
3
Hint
Constraints
This problem has five test points. The information for each test point is as follows:
| Test Point ID | ||
|---|---|---|
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | ||
| 5 |
For all test points, it is guaranteed that , , and the values of are uniformly random within the corresponding range.
It is guaranteed that the final answer does not exceed .
Translated by ChatGPT 5
京公网安备 11011102002149号