#P2120. [ZJOI2007] 仓库建设

    ID: 1329 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2007各省省选浙江动态规划优化斜率优化

[ZJOI2007] 仓库建设

Description

Company L has nn factories distributed from high to low along a mountain; factory 11 is at the summit, and factory nn is at the foot.

Because the mountain is in an inland plateau region (dry with little rain), Company L usually stacks products directly in the open air to save costs. One day, Mr. L, the president of Company L, received a call from the meteorological department and was informed that there would be a heavy rain in three days. Therefore, Mr. L decided to urgently build some warehouses at certain factories to prevent the products from getting wet.

Due to differences in terrain, the cost of building a warehouse may vary from one factory to another. Factory ii currently has pip_i finished items, and the cost of building a warehouse at factory ii is cic_i.

For factories where no warehouse is built, their products should be transported to other warehouses for storage. Since Company L’s external sales outlet is located at factory nn at the foot of the mountain, products can only be transported downhill (that is, only to the warehouse of a factory with a larger index). Of course, transportation also costs money: transporting one item over one unit of distance costs 11.

Assume that any warehouse built is large enough to hold all products. You will be given the following data:

  • The distance from factory ii to factory 11, xix_i (where x1=0x_1 = 0).
  • The current number of finished items at factory ii, pip_i.
  • The cost of building a warehouse at factory ii, cic_i.

Please help Company L find a warehouse construction plan that minimizes the total cost (construction cost + transportation cost).

Input Format

The first line contains an integer nn, the number of factories.

Lines 22 through (n+1)(n + 1) each contain three space-separated integers. On line (i+1)(i + 1), the integers are xi, pi, cix_i,~p_i,~c_i in order.

Output Format

Output a single line with one integer, the cost of the optimal plan.

3
0 5 10
5 3 100
9 6 10
32

Hint

Explanation for Sample Input/Output 11

Build warehouses at factory 11 and factory 33. The construction cost is 10+10=2010 + 10 = 20, the transportation cost is (95)×3=12(9 - 5) \times 3 = 12, and the total cost is 3232.

Constraints and Agreements

  • For 20%20\% of the testdata, it is guaranteed that n500n \leq 500.
  • For 40%40\% of the testdata, it is guaranteed that n104n \leq 10^4.
  • For 100%100\% of the testdata, it is guaranteed that 1n1061 \leq n \leq 10^6, 0xi,pi,ci<2310 \leq x_i,p_i,c_i < 2^{31}.
  • For any 1i<n1 \leq i < n, it is guaranteed that xi<xi+1x_i < x_{i + 1}.
  • Let the answer be ansans, and it is guaranteed that ans+i=1npixi<263ans + \sum\limits_{i = 1}^{n} p_ix_i < 2^{63}.

Translated by ChatGPT 5