問題
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
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
Problem credits: Brian Dean
入力
The first line of input contains
出力
Please print the minimum total cost FJ needs to spend on landscaping.
例題
4 100 200 1
1 4
2 3
3 2
4 0
210
Note that this problem has been asked in a previous USACO contest, at the silver level; however, the limits in the present version have been raised considerably, so one should not expect many points from the solution to the previous, easier version.