No.2889 Rusk
タグ : / 解いたユーザー数 97
作問者 : 👑
kemuniku
Problem Statement
There are $N$ slices of bread, numbered $1,2,\dots,N$ in order. Each slice has a front side and a back side. The deliciousness of slice $i$ is $A_i$ when neither its front nor its back is toasted, $B_i$ when only one side is toasted, and $C_i$ when both sides are toasted.
You will now toast the bread, using the toaster at most $2$ times. When using the toaster, you specify integers $l, r$ satisfying $1 \le l \le r \le N$, and for each slice whose number is between $l$ and $r$, inclusive, you can specify one side, front or back, that has not been toasted yet and toast it. The side to toast can be chosen independently for each slice, but you cannot choose a side that has already been toasted, nor can you leave a slice without toasting either side.
Find the maximum achievable value of the sum of the deliciousness of the $N$ slices.
Input
$N$ $A_1$ $A_2$ $\dots$ $A_N$ $B_1$ $B_2$ $\dots$ $B_N$ $C_1$ $C_2$ $\dots$ $C_N$
Constraints
- $1 \le N \le 2 \times 10^5$
- $1 \le A_i, B_i, C_i \le 10^9 \quad (1 \le i \le N)$
- All input values are integers.
Output
Output the answer in $1$ line.
Sample
Sample 1
Input
5 1 3 4 2 3 3 1 3 5 1 2 5 1 1 2
Output
19
It is optimal to specify $l=1, r=2$ and toast the front sides on use number $1$ of the toaster, and to specify $l=2, r=4$ and toast the back sides on use number $2$ of the toaster.
Sample 2
Input
5 6 1 2 5 4 2 5 6 3 5 1 2 4 1 1
Output
27
Sample 3
Input
1 10 1 1
Output
10
It is optimal not to use the toaster even $1$ time.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。