Logo HelloWorld信息学奥赛题库

少儿编程

时间限制:1 s 空间限制:512 MB

#1767. [USACO12MAR]园林绿化Landscaping

统计

题目描述

Farmer John is building a nicely-landscaped garden, and needs to move a large amount of dirt in the process.
The garden consists of a sequence of N flowerbeds (1 <= N <= 100), where flowerbed i initially contains A_i units of dirt. Farmer John would like to re-landscape the garden so that each flowerbed i instead contains B_i units of dirt. The A_i's and B_i's are all integers in the range 0..10.
To landscape the garden, Farmer John has several options: he can purchase one unit of dirt and place it in a flowerbed of his choice for $X. He can remove one unit of dirt from a flowerbed of his choice and have it shipped away for $Y. He can also transport one unit of dirt from flowerbed i to flowerbed j at a cost of $Z times |i-j|. Please compute the minimum total cost for Farmer John to complete his landscaping project.
有n块土地,每块有A[i]泥土,现把其改造成B[i]泥土,有3种操作:(1)花费X向任意土地增加1泥土;(2)花费Y向任意土地减少1泥土;(3)花费Z*|i-j|把土地i的1泥土运到土地j。问最小花费是多少。

输入格式:

Line 1: Space-separated integers N, X, Y, and Z (0 <= X, Y, Z <= 1000).
Lines 2..1+N: Line i+1 contains the space-separated integers A_i and B_i.

输出格式:

Line 1: A single integer giving the minimum cost for Farmer John's landscaping project.

输入样例#1:

4 100 200 1 
1 4 
2 3 
3 2 
4 0 

输出样例#1:

210