#Q191. 「一本通 5.6 练习 2」仓库建设
「一本通 5.6 练习 2」仓库建设
Description
Original source: ZJOI 2007
L Company has several factories on a mountain. Due to the mountain's location in an inland plateau area (dry with little rain), L Company usually stores its products directly outdoors to save costs. Suddenly one day, Mr. L, the president of L Company, received a call from the meteorological department informing him that a heavy rainstorm would arrive in three days. Thus, Mr. L decided to urgently build warehouses in some factories to prevent the products from being damaged by the rain.
L Company has factories on the mountain. As shown in the figure, Factory is at the mountaintop, and Factory is at the mountain base.
Due to the varying terrain, the cost of building a warehouse may differ across factories. Factory currently has finished products, and the cost of building a warehouse in this factory is . For factories without a warehouse, their products must be transported to other warehouses for storage. Since L Company's product sales office is located at Factory at the mountain base, products can only be transported downhill (i.e., only to warehouses of factories with larger indices). Of course, transporting products also incurs costs—the cost of moving one product one unit distance is . It is assumed that the capacity of all warehouses is sufficiently large to accommodate all products.
The following are known:
- The distance of Factory from Factory , denoted as (where );
- The current number of finished products in Factory , denoted as ;
- The cost of building a warehouse in Factory , denoted as .
Please help L Company 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. Next, lines follow, each containing three integers and , as described in the problem statement.
Output Format
Output a single integer, the minimum total cost achievable with the optimal plan.
Sample 1
Building warehouses in Factory and Factory incurs a construction cost of and a transportation cost of , resulting in a total cost of . If a warehouse is built only in Factory , the construction cost is , and the transportation cost is , resulting in a total cost of , which is worse than the first plan.
3
0 5 10
5 3 100
9 6 10
32
Data Range and Hints
For all data, . It is guaranteed that all and are within the int range, and intermediate calculation results will not exceed the long long range.