luogu#P3049. [USACO12MAR] Landscaping S

[USACO12MAR] Landscaping S

Background

This problem has the same statement as the problem of the same name in the 2016 Open Contest Platinum, with the only difference being the testdata constraints.

Problem Description

Farmer John (FJ) plans to build a garden and needs to move quite a bit of soil.

The garden consists of NN flowerbeds (1N1001 \leq N \leq 100), where flowerbed ii contains AiA_i units of soil. FJ wants flowerbed ii to contain BiB_i units of soil, and it is guaranteed that 0Ai,Bi100 \leq A_i, B_i \leq 10.

To achieve this goal, he can do the following:

  • Buy one unit of soil and place it in a specified flowerbed, at a cost of XX.
  • Remove one unit of soil from any flowerbed, at a cost of YY.
  • Transport one unit of soil from flowerbed ii to flowerbed jj, at a cost of ZijZ|i-j|.

Please help FJ compute the minimum cost to move the soil.

Input Format

The first line contains four integers N,X,Y,ZN, X, Y, Z (0X,Y,Z10000 \leq X, Y, Z \leq 1000).

The next NN lines each contain two integers Ai,BiA_i, B_i for the ii-th line.

Output Format

Output the minimum cost to move the soil.

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

210 

Hint

With the following plan, the minimum cost is 210210, and you can prove that no cheaper plan exists.

  • Remove one unit of soil from flowerbed 44, costing 200200.
  • Move three units of soil from flowerbed 44 to flowerbed 11, costing 3×3=93 \times 3=9.
  • Move one unit of soil from flowerbed 33 to flowerbed 22, costing 1×1=11 \times 1=1.

Translated by ChatGPT 5