#P4655. [CEOI 2017] Building Bridges
[CEOI 2017] Building Bridges
Description
There are pillars arranged in order, and each pillar has a height. The height of the -th pillar is .
Now we want to build several bridges. If a bridge is built between the -th pillar and the -th pillar, it costs .
Before building bridges, all pillars that are not used will be demolished, because they would interfere with the construction process. The cost to demolish the -th pillar is . Note that is not necessarily non-negative, because the government may want some pillars to be demolished.
Now the government wants to know the minimum total cost to connect pillar and pillar using bridges. Note that bridges cannot intersect anywhere other than at their endpoints.
Input Format
The first line contains a positive integer .
The second line contains space-separated integers, which are in order.
The third line contains space-separated integers, which are in order.
Output Format
Output one line with one integer, the minimum total cost. Note that the minimum total cost is not necessarily positive.
6
3 8 7 1 6 6
0 -1 9 1 2 0
17
Hint
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号