RESTAURANTS
As the network manager of a restaurant chain, you must choose where to open stores along the new national road. candidate positions have been preselected, and stores can be opened at any of these. For each candidate position , the expected profit from opening a store there has been calculated based on whether stores will open at neighboring positions. If no store opens at positions and , the expected profit from the store at position is . If a store opens at one of positions or , the expected profit is . If stores open at both positions and , the expected profit is ( and are not defined, and for each position , it holds that ).
Write a program that selects the positions where stores should be opened to maximize profit.
Input
The first line of input contains the number of candidate positions . The second line contains numbers, the values of , , . The third line contains numbers, the values of , , . Finally, the fourth line contains numbers, the values of , , .
Output
The output must consist of one line containing exactly one integer, the maximum profit that can be obtained
Constraints
Maximum Execution Time: 2 sec
Available Memory: 64 MB
Example of Input - Output
STDIN (restaurants.in)
8
10 9 15 8 18 12 6 8
6 5 8 7 16 10 5 7
3 6 6 12 9 4
STDOUT (restaurants.out)
61
Explanation of the Example
The optimal solution is to open restaurants at positions , , , , , and . Thus, the expected profit is .
Comments