CF1882C.Card Game
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n cards stacked in a deck. Initially, ai 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 † 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 ‡ 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?
† An integer i is odd, if there exists an integer k such that i=2k+1 .
‡ An integer i is even, if there exists an integer k such that i=2k .
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t ( 1≤t≤104 ). The description of the test cases follows.
The first line of each test case contains a single integer n ( 1≤n≤2⋅105 ).
The second line of each test case contains n integers a1,a2,…,an ( −109≤ai≤109 ).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105 .
输出格式
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 5 as follows:
- 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] .
- 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] .
- 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:
- 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] .
- 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] .
- 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:
- 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] .
- 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] .
- In the third turn, end the game with the score of 2 .