No.2196 Pair Bonus
タグ : / 解いたユーザー数 146
作問者 :
とりゐ
Problem Statement
There are $2N$ people, numbered $1, 2, \dots, 2N$. Shirotsume is going to put a red or blue hat on each of them. $1$ person wears exactly $1$ hat, which is either red or blue.
Points are awarded according to the colors of the hats.
For each $i$ $(1 \leq i \leq 2N)$, putting a red hat on person $i$ gives $A_i$ points, and putting a blue hat on them gives $B_i$ points.
In addition, for each $i$ $(1 \leq i \leq N)$, a bonus of $X_i$ points is obtained if person $2i - 1$ and person $2i$ have hats of the same color, and a bonus of $Y_i$ points is obtained if their colors differ.
What is the maximum possible score when the hat colors for the $2N$ people are chosen appropriately?
Constraints
- All input values are integers
- $1 \leq N \leq 10^5$
- $1 \leq A_i \leq 10^9$ ($1 \leq i \leq 2N$)
- $1 \leq B_i \leq 10^9$ ($1 \leq i \leq 2N$)
- $1 \leq X_i \leq 10^9$ ($1 \leq i \leq N$)
- $1 \leq Y_i \leq 10^9$ ($1 \leq i \leq N$)
Input
The input is given from standard input in the following format.$N$
$A_1$ $A_2$ $\dots$ $A_{2N}$
$B_1$ $B_2$ $\dots$ $B_{2N}$
$X_1$ $X_2$ $\dots$ $X_N$
$Y_1$ $Y_2$ $\dots$ $Y_N$
Output
Print the answer.
Print a newline at the end.Sample
Sample 1
Input
2 3 1 4 1 5 9 2 6 1 5 4 1
Output
29
Denoting a red hat by R and a blue hat by B, the assignment RBBB gives $29$ points.
The points from the hat color of each person total $3 + 9 + 2 + 6 = 20$ points. In addition, person $1$ and person $2$ have hats of different colors, giving a bonus of $Y_1 = 4$ points, and person $3$ and person $4$ have hats of the same color, giving a bonus of $X_2 = 5$ points, for a total of $29$ points.
It is not possible to obtain more points than this, so print $29$.
Sample 2
Input
4 31415 92653 58979 32384 62643 38327 95028 84197 27182 81828 45904 52353 60287 47135 26624 97757 11111 33333 55555 77777 88888 66666 44444 22222
Output
806700
Sample 3
Input
5 132369990 154684955 399557792 6898866 892085082 475405438 178727727 496378193 391115300 392312020 929620757 339762612 478146585 237867511 112947139 932164889 474129303 798212953 843175854 899264953 148258026 932749041 478171985 880111286 733483895 647484075 34641657 473409219 391218034 474131840
Output
10306590358
The answer may not fit in a 32bit integer.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。