#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 cards: , , and . You will play rounds. In each round, both players play one card, and the winner is decided by the rules: beats , beats , and beats . In round , the winner gains points and the loser gains points. If both players play the same card, it is a draw and both gain points .
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 rounds and tell you his entire plan. Starting from round , 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 times, you will be additionally deducted points.
Please compute the maximum score you can obtain.
Input Format
The first line contains an integer , the number of rounds.
The second line contains non-negative integers separated by single spaces, as described in the statement.
The third line contains non-negative integers separated by single spaces, representing the penalty for changing cards, as described in the statement. Since the game lasts for rounds, you can change cards at most times.
The fourth line contains integers separated by single spaces, representing the cards Xiao Yang plays from round to round in order. It is guaranteed that .
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 in round , and keep it unchanged in rounds . In this way, you lose rounds , but win round and gain points;
Then, you can change to in round at the cost of deducting point, and win round , gaining points.
In this way, the highest total score you can get is .
Constraints
For of the testdata, .
For of the testdata, .
For all testdata, ; and .
Translated by ChatGPT 5