#P3080. [USACO13MAR] The Cow Run G/S
[USACO13MAR] The Cow Run G/S
Description
Farmer John forgot to repair a hole in his fence, and his cows () escaped. Each minute a cow is outside the fence, she causes one dollar of damage. Farmer John must visit each cow to install a halter that calms the cow and stops the damage.
The cows are positioned at distinct locations along a straight road outside the farm. Farmer John knows the position of each cow (relative to the gate at position where he starts), with and .
Farmer John moves at one unit of distance per minute, and installing a halter is instantaneous. Determine the order in which he should visit the cows to minimize the total damage, and compute the minimum total damage cost.
Input Format
- Line 1: An integer , the number of cows.
- Lines : Line contains an integer .
Output Format
- Line 1: A single integer, the minimum total damage cost.
4
-2
-12
3
7
50
Hint
Four cows are at positions , , , and .
The optimal visit order is , , , . Farmer John arrives at position in minutes, causing dollars of damage for that cow.
He then travels to position (distance ), where the cumulative damage for that cow is dollars.
He spends more minutes to get to at a cost of dollars for that cow.
Finally, he spends minutes to go to with a cost of dollars.
The total damage is dollars.
Translated by ChatGPT 5
京公网安备 11011102002149号