luogu#P7917. [Kubic] Addition
[Kubic] Addition
Background
It is recommended to read the background of Problem B first.
Problem Description
There is an initial sequence of length . You need to perform operations. In each operation, you first choose two adjacent numbers in the current sequence and delete them ( is to the left of in the original sequence), then insert either or at the original position. After operations, exactly one number will remain. Find the maximum possible value of this remaining number.
Input Format
The first line contains an integer .
The second line contains integers, where the -th integer represents .
Output Format
Output a single line containing one integer, which is the answer.
5
-1 1 1 -1 1
3
Hint
For of the testdata, .
| |Score|||Special Property| |:-:|:-:|:-:|:-:|:-:| ||||No special restrictions|None| ||||No special restrictions|None| |||No special restrictions|No special restrictions|| |||No special restrictions||None| |||No special restrictions|No special restrictions|None|
Sample Explanation
One possible sequence of operations is as follows:
-1 1 1 -1 1
-1 1 1 -2
-1 1 3
-1 4
3
It can be proven that there is no better plan.
Input Format
Output Format
Translated by ChatGPT 5