Skip to content

tanwcw/PostmanProblem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

PostmanProblem

Post Office Problem (IOI 2000)

There is a straight highway with villages alongside the highway. The highway is represented as an integer axis, and the position of each village is identified with a single integer coordinate. There are no two villages in the same position. The distance between two positions is the absolute value of the difference of their integer coordinates. Post offices will be built in some, but not necessarily all of the villages. Obviously, a village and the post office in it have the same position. For building the post offices, their positions should be chosen so that the total sum of all distances between each village and its nearest post office is minimal.

Given the positions of the villages and the number of police offices, this program computes the least possible sum of all distances between each village and its nearest post office.

Each input case contains two lines: the first line contains two integers: the number of villages V ∈ [1,300] and the number of post office P ∈ [1,30],P ≤ V separated by a blank space. The second line contains V integers in increasing order. These V integers are the positions of the villages. For each position X it holds that 1 ≤ X ≤ 10,000.

About

Post Office Problem (IOI 2000)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages