#P2426. 删数
删数
Description
There are distinct positive integers arranged in a row. At each operation, you may remove a consecutive block of numbers () from either the left end or the right end only. After removing, numbers remain; continue applying the same operation until all numbers are removed.
Each operation has a value. Suppose you remove all numbers from position to position (inclusive). The operation value is . If you remove exactly one number, the operation value equals the value of that number.
Find how to operate to obtain the maximum possible total value, and output that maximum total value.
Input Format
- The first line contains a positive integer .
- The second line contains space-separated distinct positive integers.
Output Format
Output one line containing a single positive integer: the maximum total value.
6
54 29 196 21 133 118
768
Hint
Sample explanation and notes
It is possible to achieve the maximum value in 3 operations. First, remove the first 3 numbers: , , , with operation value 426. Second, among the remaining three numbers , remove the last number , with operation value . Third, remove the remaining two numbers and , with operation value . The total operation value is .
Constraints
, .
Translated by ChatGPT 5
京公网安备 11011102002149号