310757: CF1882C. Card Game

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Card Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

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

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

  • Choose an odd$^{\dagger}$ positive integer $i$, which is not greater than the number of cards left in the deck. Remove the $i$-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 $i$, which is not greater than the number of cards left in the deck. Remove the $i$-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 $i$ is odd, if there exists an integer $k$ such that $i = 2k + 1$.

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

Input

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

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

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

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

Output

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

ExampleInput
4
4
-4 1 -3 5
4
1 -2 3 -4
3
-1 3 -5
1
-1
Output
5
4
2
0
Note

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

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

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

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

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

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

Output

题目大意:有一叠共有 $ n $ 张卡片,每张卡片上写有一个数值 $ a_i $,这个数值在游戏过程中不会改变。游戏开始时,你的分数为 0。每轮你可以进行以下操作之一:

1. 选择一个奇数 $ i $($ i \leq n $),移除并获取第 $ i $ 张卡片,将其数值加到你的分数上,然后重新编号剩余的卡片。
2. 选择一个偶数 $ i $($ i \leq n $),移除第 $ i $ 张卡片,然后重新编号剩余的卡片。
3. 选择结束游戏。你可以在任何时候结束游戏,不必移除所有卡片。

目标是在游戏结束时获得最大分数。

输入输出数据格式:

输入:
- 第一行包含一个整数 $ t $($ 1 \leq t \leq 10^4 $),表示测试用例的数量。
- 每个测试用例的第一行包含一个整数 $ n $($ 1 \leq n \leq 2 \cdot 10^5 $)。
- 每个测试用例的第二行包含 $ n $ 个整数 $ a_1, a_2, \ldots, a_n $($ -10^9 \leq a_i \leq 10^9 $)。

保证所有测试用例的 $ n $ 之和不超过 $ 2 \cdot 10^5 $。

输出:
- 对于每个测试用例,输出一行,包含一个整数,表示游戏结束时你可以获得的最大分数。

示例:

输入:
```
4
4
-4 1 -3 5
4
1 -2 3 -4
3
-1 3 -5
1
-1
```

输出:
```
5
4
2
0
```题目大意:有一叠共有 $ n $ 张卡片,每张卡片上写有一个数值 $ a_i $,这个数值在游戏过程中不会改变。游戏开始时,你的分数为 0。每轮你可以进行以下操作之一: 1. 选择一个奇数 $ i $($ i \leq n $),移除并获取第 $ i $ 张卡片,将其数值加到你的分数上,然后重新编号剩余的卡片。 2. 选择一个偶数 $ i $($ i \leq n $),移除第 $ i $ 张卡片,然后重新编号剩余的卡片。 3. 选择结束游戏。你可以在任何时候结束游戏,不必移除所有卡片。 目标是在游戏结束时获得最大分数。 输入输出数据格式: 输入: - 第一行包含一个整数 $ t $($ 1 \leq t \leq 10^4 $),表示测试用例的数量。 - 每个测试用例的第一行包含一个整数 $ n $($ 1 \leq n \leq 2 \cdot 10^5 $)。 - 每个测试用例的第二行包含 $ n $ 个整数 $ a_1, a_2, \ldots, a_n $($ -10^9 \leq a_i \leq 10^9 $)。 保证所有测试用例的 $ n $ 之和不超过 $ 2 \cdot 10^5 $。 输出: - 对于每个测试用例,输出一行,包含一个整数,表示游戏结束时你可以获得的最大分数。 示例: 输入: ``` 4 4 -4 1 -3 5 4 1 -2 3 -4 3 -1 3 -5 1 -1 ``` 输出: ``` 5 4 2 0 ```

加入题单

上一题 下一题 算法标签: