#P4360. [CEOI 2004] 锯木厂选址

    ID: 3291 远端评测题 200ms 63MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>模拟动态规划,dp2004单调队列CEOI模拟退火斜率优化

[CEOI 2004] 锯木厂选址

Description

Along a straight line from the mountain top to the foot, there are nn 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 11 kilogram by 11 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 nn — the number of trees (2n200002 \le n \le 20000). Trees are numbered 1,2,,n1, 2, \dots, n from the mountain top down to the foot.

Each of the next nn lines contains two integers separated by a space.

The (i+1)(i+1)-th line contains wiw_i — the weight of the ii-th tree (in kilograms), and did_i — the distance between the ii-th and the (i+1)(i+1)-th tree, with 1wi100001 \le w_i \le 10000, 0di100000 \le d_i \le 10000.

For the last tree, dnd_n denotes the distance from tree nn 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 2×1092 \times 10^9 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 1155: n200n \le 200.
  • Test points 6677: n1000n \le 1000.
  • Test points 771313: 2n200002 \le n \le 20000.

Translated by ChatGPT 5