#P17015. [GESP202606 七级] 消消乐
[GESP202606 七级] 消消乐
Problem Description
You are given an array consisting of integers. Each time, you may perform the following operation on the array until becomes empty:
- Choose an element in , gain a score equal to the sum of its adjacent elements on both sides, and then delete this element from .
In particular, if an adjacent element does not exist, its value is considered to be . For example, for , you can do the following operations:
- Choose element , gain a score of , after deleting we have ;
- Choose element , gain a score of , after deleting we have ;
- Choose element , gain a score of , after deleting the array becomes empty.
What is the maximum possible total score you can obtain?
Input Format
The first line contains a positive integer , representing the length of the array.
The second line contains non-negative integers , representing the integers in the array .
Output Format
Output one line containing one integer, representing the maximum total score you can obtain.
6
1 6 3 2 9 1
55
5
3 1415 926 53 58
5771
Hint
Constraints
For of the testdata, it is guaranteed that and .
For all testdata, it is guaranteed that and .
Translated by ChatGPT 5