CF1882C.Card Game

普及/提高-

通过率:0%

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 .

输入格式

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

The first line of each test case contains a single integer nn ( 1n21051 \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 ( 109ai109-10^{9} \le a_i \le 10^{9} ).

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \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 .
首页