문제
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.