PDP-23 (2011) - Camp common - 2 (restaurants)

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 2.0s
Memory limit: 64M

Author:
Problem types
Allowed languages
C, C++, Java, Pascal, Python

RESTAURANTS

As the network manager of a restaurant chain, you must choose where to open stores along the new national road. N candidate positions have been preselected, and stores can be opened at any of these. For each candidate position 1iN, 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 i1 and i+1, the expected profit from the store at position i is ai. If a store opens at one of positions i1 or i+1, the expected profit is bi. If stores open at both positions i1 and i+1, the expected profit is ci (c1 and cN are not defined, and for each position i, it holds that aibici0).

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 N. The second line contains N numbers, the values of a1, ..., aN. The third line contains N numbers, the values of b1, ..., bN. Finally, the fourth line contains N2 numbers, the values of c2, ..., cN1.

Output

The output must consist of one line containing exactly one integer, the maximum profit that can be obtained

Constraints

2N1.000.000
0cibiai1.000
Maximum Execution Time: 2 sec
Available Memory: 64 MB

Example of Input - Output

STDIN (restaurants.in)

Copy
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)

Copy
61
Explanation of the Example

The optimal solution is to open restaurants at positions 1, 3, 5, 6, 7, and 8. Thus, the expected profit is 61 (10+0+15+0+16+9+4+7).


Comments

There are no comments at the moment.