#P10381. 「HOI R1」杂赛选比
「HOI R1」杂赛选比
Background
You are right, but when Little was playing CF, he mistook Earn or Unlock as the weird parody below, wasted 2 hours, and had to leave with regret. Hope everyone can take this as a warning.
Problem Description
Given an array of length , initially only is unlocked. Now there is an integer with initial value . Little plays a game on this array:
- If is not unlocked, the game ends.
- Otherwise, he can either set to unlocked, or gain coins (if then he cannot unlock any element), and then increase by .
Please find the maximum number of coins you can obtain after the game ends.
Input Format
This problem has multiple test cases.
The first line contains an integer , the number of test cases.
For each test case, the first line contains a positive integer .
The next line contains non-negative integers .
Output Format
For each test case, output one number per line, representing the answer.
3
2
1 2
5
2 4 5 0 1
4
0 4 4 4
2
9
0
1
10
1 1 4 5 1 4 1 9 1 9
26
Hint
Sample 1 Explanation
For the first test case, you can unlock , then gain coins. For the third test case, you cannot unlock , so you can only gain coins.
For the second test case, you can unlock and gain coins.
Sample 2 Explanation
Using positions for unlocking is the optimal strategy.
Constraints
For of the data, , , .
| Test Point ID | Special Property | |||
|---|---|---|---|---|
| / | ||||
| / | ||||
Translated by ChatGPT 5