#P4360. [CEOI 2004] 锯木厂选址
[CEOI 2004] 锯木厂选址
Description
Along a straight line from the mountain top to the foot, there are old trees. The locals have decided to cut them down. To avoid wasting any wood, once a tree is felled, the wood must be transported to a sawmill.
Lumber can only be transported downhill. There is one sawmill at the foot of the mountain. Two additional sawmills will be newly built along the mountain road. You must decide where to build these two sawmills so that the total transportation cost is minimized. Assume it costs one cent to transport kilogram by meter.
Your task is to write a program that reads the number of trees and their weights and positions from the input, and computes the minimal transportation cost.
Input Format
The first line contains a positive integer — the number of trees (). Trees are numbered from the mountain top down to the foot.
Each of the next lines contains two integers separated by a space.
The -th line contains — the weight of the -th tree (in kilograms), and — the distance between the -th and the -th tree, with , .
For the last tree, denotes the distance from tree to the sawmill at the foot of the mountain. It is guaranteed that the total cost of transporting all trees to the sawmill at the foot of the mountain is less than cents.
Output Format
Output the minimal transportation cost.
9
1 2
2 1
3 3
1 1
3 2
1 6
2 1
1 2
1 1
26
Hint
The sample illustration; black dots represent sawmills.

Constraints:
- Test points –: .
- Test points –: .
- Test points –: .
Translated by ChatGPT 5
京公网安备 11011102002149号