Codeforces Round 1068 (Div. 2)
B
Niko's Tactical Cards
Codeforces
1100
原题
← AC →
翻译中…

Niko is playing a game. Her score is denoted by an integer $k$ which is $0$ initially.

翻译中…

The game has $n$ turns. On the $i$-th turn, Niko is given a red card with an integer $a_i$ on it, as well as a blue card with an integer $b_i$ on it. She must choose exactly one of the cards and update her score according to her choice:

翻译中…
  • If she chooses the red card, her score becomes $k - a_i$, where $k$ is her score before the turn.
  • If she chooses the blue card, her score becomes $b_i - k$, where $k$ is her score before the turn.
翻译中…

After this, the game proceeds to the next turn, or ends if it is the $n$-th turn.

翻译中…

Your task is to find the maximum possible score Niko can obtain at the end of the game.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^3$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($1 \le n \le 10^5$) — the number of turns.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).

翻译中…

The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ($-10^9 \le b_i \le 10^9$).

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

翻译中…

Output

翻译中…

For each test case, output a single integer — the maximum possible score Niko can obtain at the end of the game.

翻译中…

Note

翻译中…

In the first test case, one optimal strategy is as follows:

翻译中…

Turn0123Card Chosen—BlueRedRedScore$0$$-3 - 0 = -3$$-3 - (-8) = 5$$5 - (-1) = 6$

翻译中…

In the second test case, one optimal strategy is as follows:

翻译中…

Turn012345Card Chosen—BlueBlueBlueBlueRedScore$0$$-5$$8$$-9$$13$$12$

翻译中…

样例

Input #1
3
3
4 -8 -1
-3 -7 0
5
-3 1 0 7 1
-5 3 -1 4 -5
5
-7 7 5 4 9
-9 -3 3 2 2
Output #1
6
12
27
InputCopy OutputCopy
题目信息
题号
2173B
时间限制
1.5 s
内存限制
256 MB
标签
动态规划
贪心
数学

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