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 flowerbeds (), where flowerbed contains units of soil. FJ wants flowerbed to contain units of soil, and it is guaranteed that .
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 .
- 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 for the -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 , and you can prove that no cheaper plan 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