#Q189. 「一本通 5.6 例 4」Cats Transport
「一本通 5.6 例 4」Cats Transport
Description
Original problem from: Codeforces Round #185 (Div. 1) B.
Little S is a farmer who owns cats and employs caretakers. There is a straight road on the farm with mountains numbered from to . The distance between the -th mountain and the -th mountain is . All caretakers live on mountain .
One day, the cats went out to play. The -th cat went to mountain and played until time , then waited in place for a caretaker to pick it up. The caretakers must retrieve all the cats. Each caretaker walks along the road from mountain to mountain , picking up all cats that are already waiting on each mountain. The caretakers take time to walk, moving at a speed of unit distance per unit time. The time taken to pick up cats on each mountain is negligible, and each caretaker can carry an infinite number of cats.
For example, suppose there are two mountains unit apart, and a cat plays on mountain until time before waiting. If a caretaker departs from mountain at time or , they can pick up the cat, with the cat's waiting time being or , respectively. However, if the caretaker departs at time , they will pass mountain at time and cannot pick up the cat that is still playing at that time.
Your task is to plan the departure time for each caretaker from mountain such that the total waiting time of all cats is minimized. The departure time of a caretaker can be negative.
Input Format
The first line contains three integers , , ;
The second line contains positive integers , representing the distance between the -th mountain and the -th mountain;
The next lines each contain two integers and .
Output Format
Output an integer representing the answer.
Sample 1
4 6 2
1 3 5
1 0
2 1
4 9
1 10
2 10
3 12
3
Data Range and Hints
For all data, , , , , , and .