#Q194. 「一本通 5.6 练习 5」锯木厂选址
「一本通 5.6 练习 5」锯木厂选址
Description
Original source: CEOI 2004
From the top of the mountain to the bottom along a straight line, there are old trees planted. The local government has decided to cut them down. To avoid wasting any timber, the trees must be transported to sawmills after being felled.
The timber can only be transported downhill. There is a sawmill at the foot of the mountain. Two additional sawmills will be newly built along the mountain path. You must decide where to build these two sawmills to minimize the total transportation cost. It is assumed that transporting one kilogram of timber per meter costs one cent.
Your task is to write a program that reads the number of trees, their weights, and positions, and calculates the minimum transportation cost.
Input Format
The first line of input is a positive integer , representing the number of trees. The trees are labeled from to from the mountain top to the foot.
The next lines each contain two integers and . These represent the weight (in kilograms) of the -th tree and the distance between the -th tree and the -th tree, respectively. The last number represents the distance from the -th tree to the sawmill at the foot of the mountain.
Output Format
Output only one number, representing the minimum transportation cost.
Sample 1
The figure below illustrates the optimal sawmill locations for the sample input. Trees are represented by circles, and sawmills are marked in black. The result is:

9
1 2
2 1
3 3
1 1
3 2
1 6
2 1
1 2
1 1
26
Data Range and Hints
For points of the data, $2\le n\le 2\times 10^4, 1\le w_i\le 10^4, 0\le d_i\le 10^4$. It is guaranteed that the cost to transport all trees to the sawmill at the foot of the mountain is less than cents. (This part of the data is the original dataset.)
For the remaining points of the data, , and all calculations can be performed within 64-bit signed integers.