AtCoder Grand Contest 048
B
Bracket Score
AtCoder
⌀ 1902
原题
← AC →
翻译中…

Problem Statement

翻译中…

In this problem, we consider strings consisting of (, ), [, and ].

翻译中…

A string $x$ is said to be a good parentheses sequence if and only if one of the following conditions is satisfied:

翻译中…
  • $x$ is an empty sequence.
  • There is a good parentheses sequence $s$ such that concatenating (, $s$, and ) in this order results in $x$.
  • There is a good parentheses sequence $s$ such that concatenating [, $s$, and ] in this order results in $x$.
  • There are non-empty good parentheses sequences $s$ and $t$ such that concatenating $s$ and $t$ in this order results in $x$.
翻译中…

For example, [], ([()]), and ()[()] are good parentheses sequences, but neither ()) nor ([)] is a good parentheses sequence.

翻译中…

Given are an even number $N$ and integer sequences $A$ and $B$ of length $N$ each. Here, we define a score for a good parentheses sequence of length $N$, $s=s_1s_2\cdots s_N$, as follows:

翻译中…
  • The score for $s$ is the sum of the scores of its characters.
  • The score for the $i$-th character ($1 \leq i \leq N$) is $A_i$ if $s_i$ is ( or ), and $B_i$ if $s_i$ is [ or ].
翻译中…

Find the maximum possible score for a good parentheses sequence of length $N$.

翻译中…

Constraints

翻译中…
  • $2 \leq N \leq 10^5$
  • $N$ is an even number.
  • $1 \leq A_i \leq 10^9$
  • $1 \leq B_i \leq 10^9$
  • All numbers in input are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
A_1 A_2 \cdots A_N
B_1 B_2 \cdots B_N

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
4
4 2 3 1
2 3 2 4
Output #1
12
For $s=$`()[]`, the score is $A_1+A_2+B_3+B_4=12$, which is the maximum possible value.
Input #2
10
866111664 844917655 383133839 353498483 472381277 550309930 378371075 304570952 955719384 705445072
178537096 218662351 231371336 865935868 579910117 62731178 681212831 16537461 267238505 318106937
Output #2
6629738472
题目信息
题号
agc048_b
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。