CF1882C.Card Game

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are nn cards stacked in a deck. Initially, aia_{i} is written on the ii-th card from the top. The value written on a card does not change.

You will play a game. Initially your score is 00. In each turn, you can do one of the following operations:

  • Choose an odd†^{\dagger} positive integer ii, which is not greater than the number of cards left in the deck. Remove the ii-th card from the top of the deck and add the number written on the card to your score. The remaining cards will be reindexed starting from the top.
  • Choose an even‡^{\ddagger} positive integer ii, which is not greater than the number of cards left in the deck. Remove the ii-th card from the top of the deck. The remaining cards will be reindexed starting from the top.
  • End the game. You can end the game whenever you want, you do not have to remove all cards from the initial deck.

What is the maximum score you can get when the game ends?

†^{\dagger} An integer ii is odd, if there exists an integer kk such that i=2k+1i = 2k + 1.

‡^{\ddagger} An integer ii is even, if there exists an integer kk such that i=2ki = 2k.

牌堆中有 nn 张卡片。初始时,从上往下数第 ii 张卡片上写着数字 aia_{i}。每张卡片上的数值不会改变。

你将进行一局游戏。初始时你的得分为 00。在每一回合中,你可以执行以下操作之一:

  • 选择一个奇数†^{\dagger} 正整数 ii,且 ii 不超过当前牌堆中剩余的卡片数量。移除牌堆顶部起第 ii 张卡片,并将该卡片上的数字加到你的得分中。剩余卡片将从顶部开始重新编号(即原第 i+1i+1 张变为新第 ii 张,依此类推)。
  • 选择一个偶数‡^{\ddagger} 正整数 ii,且 ii 不超过当前牌堆中剩余的卡片数量。移除牌堆顶部起第 ii 张卡片。剩余卡片将从顶部开始重新编号。
  • 结束游戏。你可以在任意时刻结束游戏,不必移除初始牌堆中的所有卡片。

当游戏结束时,你能获得的最大得分是多少?

†^{\dagger} 若存在整数 kk 使得 i=2k+1i = 2k + 1,则称整数 ii 为奇数。

‡^{\ddagger} 若存在整数 kk 使得 i=2ki = 2k,则称整数 ii 为偶数。

输入格式

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

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^{5}).

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}).

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^{5}.

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

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^{5})。

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

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^{5}。

输出格式

For each test case, print a single integer — the maximum score you can get when the game ends.

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

输入输出样例

  • 输入#1

    4
    4
    -4 1 -3 5
    4
    1 -2 3 -4
    3
    -1 3 -5
    1
    -1

    输出#1

    5
    4
    2
    0

说明/提示

In the first test case, one can get the score of 55 as follows:

  1. In the first turn, choose i=2i=2. Your score remains 00 and the numbers written on the cards from the top will become [−4,−3,5][-4, -3, 5].
  2. In the second turn, choose i=3i=3. Your score will become 55 and the numbers written on the cards from the top will become [−4,−3][-4, -3].
  3. In the third turn, end the game with the score of 55.

In the second test case, one can get the score of 44 as follows:

  1. In the first turn, choose i=3i=3. Your score will become 33 and the numbers written on the cards from the top will become [1,−2,−4][1, -2, -4].
  2. In the second turn, choose i=1i=1. Your score will become 44 and the numbers written on the cards from the top will become [−2,−4][-2, -4].
  3. In the third turn, end the game with the score of 44.

In the third test case, one can get the score of 22 as follows:

  1. In the first turn, choose i=1i=1. Your score will become −1-1 and the numbers written on the cards from the top will become [3,−5][3, -5].
  2. In the second turn, choose i=1i=1. Your score will become 22 and the numbers written on the cards from the top will become [−5][-5].
  3. In the third turn, end the game with the score of 22.

在第一个测试用例中,可以按如下方式获得分数 55:

  1. 在第一轮中,选择 i=2i=2。此时你的分数保持为 00,而从上到下写在卡片上的数字变为 [−4,−3,5][-4, -3, 5]。
  2. 在第二轮中,选择 i=3i=3。此时你的分数变为 55,而从上到下写在卡片上的数字变为 [−4,−3][-4, -3]。
  3. 在第三轮中,以分数 55 结束游戏。

在第二个测试用例中,可以按如下方式获得分数 44:

  1. 在第一轮中,选择 i=3i=3。此时你的分数变为 33,而从上到下写在卡片上的数字变为 [1,−2,−4][1, -2, -4]。
  2. 在第二轮中,选择 i=1i=1。此时你的分数变为 44,而从上到下写在卡片上的数字变为 [−2,−4][-2, -4]。
  3. 在第三轮中,以分数 44 结束游戏。

在第三个测试用例中,可以按如下方式获得分数 22:

  1. 在第一轮中,选择 i=1i=1。此时你的分数变为 −1-1,而从上到下写在卡片上的数字变为 [3,−5][3, -5]。
  2. 在第二轮中,选择 i=1i=1。此时你的分数变为 22,而从上到下写在卡片上的数字变为 [−5][-5]。
  3. 在第三轮中,以分数 22 结束游戏。

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

首页