Damaged Flowers
One day, a farmer left his cows to graze in the pasture, as usual. However, when he returned, he found them eating the flowers in his garden! Wanting to minimize the damage from now on, the farmer decided to immediately move each cow back to the barn.
Each cow is at a position that is minutes away from the barn and destroys flowers per minute. No matter how hard he tries, the farmer can only move one cow at a time. Moving cow requires a total of minutes ( to take the cow to the barn and to return).
The farmer starts from the garden, moves a cow to the barn, returns, and immediately moves the next cow.
Problem
Write a program that finds the order in which the farmer must move the cows so that the minimum possible number of flowers are destroyed.
Input
Line : contains the integer .
Lines to : each contains two integers separated by spaces, and , describing the characteristics of cow .
Output
Line : contains a single number, the minimum number of damaged flowers.
Example of Input - Output Files:
STDIN (flowers.in)
6
3 1
2 5
2 3
3 2
4 1
1 6
STDOUT (flowers.out)
86
Constraints
- .
- .
- .
Comments