#P15458. 【MX-X25-T2】『FeOI-5』2 的次幂
【MX-X25-T2】『FeOI-5』2 的次幂
Problem Description
You are given a non-negative integer sequence of length . You may perform the following operation any number of times:
- Choose an interval (where and may be equal).
- Let , and let be the largest non-negative integer such that (if then ).
- You gain coins, and delete . After that, and are concatenated, i.e., the new length of becomes .
Find the maximum number of coins you can obtain.
Input Format
The first line contains two integers , representing the subtask ID of the test point (the samples guarantee ) and the number of test cases.
For each test case, the input contains two lines:
- The first line contains an integer .
- The second line contains integers representing the sequence .
Output Format
For each test case, output one line with one integer representing the answer.
0 1
5
3 2 1 1 4
5
0 1
12
1 0 3 2 2 1 4 5 6 8 7 9
19
Hint
Sample 1 Explanation
First operation: choose interval . Then , you gain coin, and the sequence becomes 3 1 1 4 after the operation.
Second operation: choose interval . Then , you gain coins, and the sequence becomes 4 after the operation.
Third operation: choose interval . Then , you gain coins, and the sequence becomes an empty sequence after the operation.
In total you gain coins. It can be proven that this is the maximum number of coins that can be obtained.
Constraints
For all testdata, , , .
| Subtask ID | Special Property | Score | |
|---|---|---|---|
| None | |||
| ,there does not exist such that | |||
| None | |||
Translated by ChatGPT 5