#P2120. [ZJOI2007] 仓库建设
[ZJOI2007] 仓库建设
Description
Company L has factories distributed from high to low along a mountain; factory is at the summit, and factory 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 currently has finished items, and the cost of building a warehouse at factory is .
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 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 .
Assume that any warehouse built is large enough to hold all products. You will be given the following data:
- The distance from factory to factory , (where ).
- The current number of finished items at factory , .
- The cost of building a warehouse at factory , .
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 , the number of factories.
Lines through each contain three space-separated integers. On line , the integers are 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
Build warehouses at factory and factory . The construction cost is , the transportation cost is , and the total cost is .
Constraints and Agreements
- For of the testdata, it is guaranteed that .
- For of the testdata, it is guaranteed that .
- For of the testdata, it is guaranteed that , .
- For any , it is guaranteed that .
- Let the answer be , and it is guaranteed that .
Translated by ChatGPT 5
京公网安备 11011102002149号