#P2748. [USACO16OPEN] Landscaping P

[USACO16OPEN] Landscaping P

Description

Farmer John plans to build a garden, and he needs to move a lot of soil.

The garden consists of NN flowerbeds (1N1051 \leq N \leq 10^5). Flowerbed ii initially contains AiA_i units of soil. FJ wants flowerbed ii to contain BiB_i units of soil. It is guaranteed that 0Ai,Bi100 \leq A_i,B_i \leq 10.

To achieve this, he can do the following:

  • Buy one unit of soil and put it into 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,Y1080 \leq X,Y \leq 10^80Z10000 \leq Z \leq 1000).

The next NN lines each contain two integers Ai,BiA_i,B_i on line ii.

Output Format

Output the minimum cost to move the soil.

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

Hint

Using the plan below, the minimum cost is 210210. It can be proven that no plan with a smaller cost 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