Cutting down trees
Time limit2sMemory limit512 MB
Cut every tree to height 0; each recharge costs b_i where i is the largest index already felled, and you must minimize total cost given increasing a_i and decreasing b_i.
Problem
There are trees with heights , and you want to cut every one of them down with a chainsaw.
Each time you use the chainsaw on tree , the height of that tree drops by 1. The chainsaw has to be recharged after every use, and the price of one recharge depends on the largest index among the trees whose height already reached 0. If that index is , one recharge costs . While no tree has height 0, the chainsaw cannot be recharged. The chainsaw is charged at the very start.
Given the heights and the recharge cost of each tree, write a program that computes the minimum total recharge cost needed to bring every tree down to height 0.
Input
The first line contains (). The second line contains and the third line contains . (, )
The input satisfies , , , and .
Output
Print the minimum total recharge cost needed to cut down every tree.