P22430 [CodeChef] FASTFOOD
普及
题目描述

Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

Chef owns a fast food shop that is currently located in a city called Chefland. He is planning to move his shop to a bigger city called Chefabad. There are $N$ consecutive days (numbered $1$ through $N$) such that the move can be done before day $1$, after day $N$ or between any two consecutive days. Moving the shop takes zero time. Chef wants to time the move in a way thay maximises his profit during these $N$ days.

For each $i$ ($1 ≤ i ≤ N$), we know that if Chef's shop is in Chefland on the $i$-th day, he earns $A_{i}$ coins, while if it is in Chefabad on this day, he earns $B_{i}$ coins. Find the maximum profit Chef can make if he optimally chooses the time when the shop should move. Note that once the shop has moved to Chefabad, it cannot return to Chefland.

------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
The third line contains $N$ space-separated integers $B_{1}, B_{2}, \ldots, B_{N}$.

------ Output ------
For each test case, print a single line containing one integer ― the maximum profit.

------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ A_{i}, B_{i} ≤ 10^{4}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{6}$

------ Subtasks ------
Subtask #1 (50 points):
$1 ≤ N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $10,000$

Subtask #2 (50 points): original constraints

----- Sample Input 1 ------
3
3
2 3 2
10 3 4
4
7 5 3 4
2 3 1 3
2
10 1
1 10
----- Sample Output 1 ------
17
19
20
----- explanation 1 ------
Example case 1: The best time to move is before the first day.

Example case 2: The best time to move is after the last day.

Example case 3: The best time to move is after the first day.

输入格式

见题面

输出格式

见题面

样例输入
3 3 2 3 2 10 3 4 4 7 5 3 4 2 3 1 3 2 10 1 1 10
样例输出
17 19 20