logo AlgoBeat OnlineJudge
登录 注册

#202139. [USACO13MAR] The Cow Run G/S

内存限制:125 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Farmer John has forgotten to repair a hole in the fence on his farm, and his cows () have escaped and gone on a rampage! Each minute a cow is outside the fence, she causes one dollar worth of damage. FJ must visit each cow to install a halter that will calm the cow and stop the damage.

Fortunately, the cows are positioned at distinct locations along a straight line on a road outside the farm. FJ knows the location of each cow (, ) relative to the gate (position ) where FJ starts.

FJ moves at one unit of distance per minute and can install a halter instantly. Please determine the order that FJ should visit the cows so he can minimize the total cost of the damage; you should compute the minimum total damage cost in this case.

输入格式

  • Line : The number of cows, .
  • Lines : Line contains the integer .

输出格式

  • Line : The minimum total cost of the damage.

样例

样例输入 1

4 
-2 
-12 
3 
7 

样例输出 1

50 

数据范围与提示

Four cows placed in positions: , , , and .

The optimal visit order is , , , . FJ arrives at position in minutes for a total of dollars in damage for that cow.

He then travels to position (distance: ) where the cumulative damage is dollars for that cow.

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.