Fardin is a secret Santa! Every Christmas, Fardin dresses up as a polar bear and spreads his good will to homes which do not have chimneys. He accomplishes this by throwing presents through the windows (sometimes the windows are not open). This Christmas, Fardin comes across a particularly interesting building. Approached from the side, the building has only one column, and is 100 stories tall. There are windows on certain floors, and Fardin has bought specific gifts for each of these floors with windows; each gift
Input Specification
Line 1: one integer
Next
It is guaranteed that no two presents are for the same floor.
Output Specification
Output one integer, the minimum amount of stress Fardin must bear to deliver all the presents. The output is guaranteed to fit in a 32-bit integer.
Sample Input
3
100 1
1 200
2 1
Sample Output
20505
Explanation for Sample Output
There are three presents Fardin must deliver. One must go to floor 100 and has weight 1, one must go to floor 1 and weighs 200, and one must go to floor 2 and weighs 1. In the optimal strategy, Fardin goes directly to floor 1, taking 100 seconds, and throws the present through in another second. The total stress delivering the first present is
Comments
should we assume you mean the sum of the weights of the gifts?
yes
I <3 you Weiwei
that took me way too long to do :(