CF2173B.Niko's Tactical Cards

普及-

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Niko is playing a game. Her score is denoted by an integer kk which is 00 initially.

The game has nn turns. On the ii-th turn, Niko is given a red card with an integer aia_i on it, as well as a blue card with an integer bib_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−aik - a_i, where kk is her score before the turn.
  • If she chooses the blue card, her score becomes bi−kb_i - k, where kk is her score before the turn.

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

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

尼可正在玩一个游戏。她的得分用一个整数 kk 表示,初始值为 00。

游戏共进行 nn 轮。在第 ii 轮中,尼可会收到一张红色卡片,上面印有一个整数 aia_i;同时还会收到一张蓝色卡片,上面印有一个整数 bib_i。她必须恰好选择其中一张卡片,并根据所选卡片更新自己的得分:

  • 若她选择红色卡片,则她的得分变为 k−aik - a_i,其中 kk 是本轮开始前的得分;
  • 若她选择蓝色卡片,则她的得分变为 bi−kb_i - k,其中 kk 是本轮开始前的得分。

随后游戏进入下一轮,若当前已是第 nn 轮,则游戏结束。

你的任务是求出尼可在游戏结束时所能获得的最高可能得分。

输入格式

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

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

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (−109≤ai≤109-10^9 \le a_i \le 10^9).

The third line of each test case contains nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n (−109≤bi≤109-10^9 \le b_i \le 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1031 \le t \le 10^3)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5)—— 表示回合数。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(−109≤ai≤109-10^9 \le a_i \le 10^9)。

每个测试用例的第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(−109≤bi≤109-10^9 \le b_i \le 10^9)。

保证所有测试用例的 nn 之和不超过 10510^5。

输出格式

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

对于每个测试用例,输出一个整数——Niko 在游戏结束时所能获得的最高分数。

输入输出样例

  • 输入#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

    输出#1

    6
    12
    27

说明/提示

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

Turn

0

1

2

3

Card Chosen

—

Blue

Red

Red

Score

00

−3−0=−3-3 - 0 = -3

−3−(−8)=5-3 - (-8) = 5

5−(−1)=65 - (-1) = 6

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

Turn

0

1

2

3

4

5

Card Chosen

—

Blue

Blue

Blue

Blue

Red

Score

00

−5-5

88

−9-9

1313

1212

在第一个测试用例中,一种最优策略如下所示:

轮次

0

1

2

3

所选卡片

—

蓝色

红色

红色

得分

00

−3−0=−3-3 - 0 = -3

−3−(−8)=5-3 - (-8) = 5

5−(−1)=65 - (-1) = 6

在第二个测试用例中,一种最优策略如下所示:

轮次

0

1

2

3

4

5

所选卡片

—

蓝色

蓝色

蓝色

蓝色

红色

得分

00

−5-5

88

−9-9

1313

1212

输入解题思路,AI测评打分。不知道怎么写?

首页