#P1889. 士兵站队
士兵站队
Description
On a grid-partitioned playground, soldiers are scattered on grid points, each represented by integer coordinates .
A soldier can move one step up, down, left, or right along grid edges, but at any moment, at most one soldier may occupy any grid point.
By order, they must form a neat horizontal lineup, that is, the sequence . Determine how to choose and so that the total number of steps taken by all soldiers to line up is minimized.
Input Format
The first line contains an integer — the number of soldiers.
Lines to each contain integers. On line , the integers denote the coordinates of the -th soldier.
Output Format
Output a single integer on one line — the answer.
5
1 2
2 2
1 3
3 -2
3 3
8
Hint
Constraints: For of the testdata, it is guaranteed that , .
Translated by ChatGPT 5
京公网安备 11011102002149号