#P2748. [USACO16OPEN] Landscaping P
[USACO16OPEN] Landscaping P
Background
This problem is the same in meaning as the Silver Division problem with the same name from the March 2012 Monthly Contest. The only difference is the constraints.
Problem Description
Farmer John plans to build a garden, and he needs to move a lot of soil.
The garden consists of flowerbeds (). Flowerbed initially contains units of soil. FJ wants flowerbed to contain units of soil. It is guaranteed that .
To achieve this, he can do the following:
- Buy one unit of soil and put it into a specified flowerbed, at a cost of .
- Remove one unit of soil from any flowerbed, at a cost of .
- Transport one unit of soil from flowerbed to flowerbed , at a cost of .
Please help FJ compute the minimum cost to move the soil.
Input Format
The first line contains four integers (,).
The next lines each contain two integers on 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
Using the plan below, the minimum cost is . It can be proven that no plan with a smaller cost exists.
- Remove one unit of soil from flowerbed , costing .
- Move three units of soil from flowerbed to flowerbed , costing .
- Move one unit of soil from flowerbed to flowerbed , costing .
Translated by ChatGPT 5