#P10111. [GESP202312 七级] 纸牌游戏

[GESP202312 七级] 纸牌游戏

Background

Related multiple-choice and true/false problems: https://ti.luogu.com.cn/problemset/1139.

Problem Description

You and Xiao Yang are playing a card game.

Each of you has 33 cards: 00, 11, and 22. You will play NN rounds. In each round, both players play one card, and the winner is decided by the rules: 11 beats 00, 22 beats 11, and 00 beats 22. In round ii, the winner gains 2×ai2 \times a_i points and the loser gains 00 points. If both players play the same card, it is a draw and both gain aia_i points (i=1,2,,N)(i=1,2,\cdots,N).

After playing for a while, you feel this is too boring, so both of you make different new rules for yourselves. Before the whole game starts, Xiao Yang will decide all of his plays for all NN rounds and tell you his entire plan. Starting from round 22, you must either keep playing the same card as in the previous round, or record one “card change”. At the end of the game, if you changed cards tt times, you will be additionally deducted b1++btb_1+\cdots+b_t points.

Please compute the maximum score you can obtain.

Input Format

The first line contains an integer NN, the number of rounds.

The second line contains NN non-negative integers a1,,aNa_1,\cdots,a_N separated by single spaces, as described in the statement.

The third line contains N1N-1 non-negative integers b1,,bN1b_1,\cdots,b_{N-1} separated by single spaces, representing the penalty for changing cards, as described in the statement. Since the game lasts for NN rounds, you can change cards at most N1N-1 times.

The fourth line contains NN integers c1,,cNc_1,\cdots,c_N separated by single spaces, representing the cards Xiao Yang plays from round 11 to round NN in order. It is guaranteed that ci{0,1,2}c_i\in\{0,1,2\}.

Output Format

Output one integer in one line, the maximum score you can obtain.

4
1 2 10 100
1 100 1
1 1 2 0
219
6
3 7 2 8 9 4
1 3 9 27 81
0 1 2 1 2 0
56

Hint

Sample Explanation 1

You can play 00 in round 11, and keep it unchanged in rounds 2,32,3. In this way, you lose rounds 1,21,2, but win round 33 and gain 2×10=202\times10=20 points;

Then, you can change to 11 in round 44 at the cost of deducting 11 point, and win round 44, gaining 2×100=2002\times100=200 points.

In this way, the highest total score you can get is 20+2001=21920+200-1=219.

Constraints

For 30%30\% of the testdata, N15N\le15.

For 60%60\% of the testdata, N100N\le100.

For all testdata, N1,000N \le 1,000; and 0ai,bi1060 \le a_i,b_i \le 10^6.

Translated by ChatGPT 5