#P14481. 星命定轨
星命定轨
Description
wwwwwza is a data structure expert, and today she found a data structure problem.
You have a sequence of length indexed starting from , consisting of non-negative integers, and a variable . Initially, . You can perform the following operation multiple times:
- Choose three adjacent numbers in , then take the minimum of the numbers to the left of and to the right of (if they exist) with . Then remove these three numbers. This operation adds to .
Your task is to maximize .
Input Format
The first line contains an integer .
The second line contains integers, where the -th integer is .
Output Format
Output one line representing the answer.
10
2 4 0 7 5 7 6 9 6 8
19
9
9 9 8 2 4 4 3 5 3
18
Hint
Sample Explanation 1
Initially, the sequence is .
Perform these operations:
-
Choose to remove the three numbers starting from the 7th position . Now the array becomes . However, the 6th and 7th positions need to take the minimum with . Now the array becomes .
-
Choose to remove the three numbers starting from the 5th position . Now the array becomes . However, the 4th and 5th positions (non-existent) need to take the minimum with . Now the array becomes .
-
Choose to remove the three numbers starting from the 1st position . Now the array becomes . However, the 0th position (non-existent) and the 1st position need to take the minimum with . Now the array becomes .
, and it can be proven that you cannot obtain a scheme where .
Note that you don't need to empty the array.
Data Range
The test points are equally weighted with 10 points each.
| Test Data | |
|---|---|
For all data, .
Please note the constant factor differences between different algorithms. The time and space limits for this problem are twice that of the standard solution.
Please note the special time limit for this problem.
京公网安备 11011102002149号