Codeforces Round 825 (Div. 2)
E
Swap and Take
Codeforces
2600
原题
← D→
翻译中…

You're given an array consisting of $n$ integers. You have to perform $n$ turns.

翻译中…

Initially your score is $0$.

翻译中…

On the $i$-th turn, you are allowed to leave the array as it is or swap any one pair of $2$ adjacent elements in the array and change exactly one of them to $0$(and leave the value of other element unchanged) after swapping. In either case(whether you swap or not), after this you add $a_i$ to your score.

翻译中…

What's the maximum possible score you can get?

翻译中…

Input

翻译中…

The first line contains a single integer $n$ ($2 \le n \le 500$).

翻译中…

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$).

翻译中…

Output

翻译中…

Print a single integer — the maximum possible score.

翻译中…

Note

翻译中…

In the first example, to get the maximum score we do as follows. Do nothing on the first turn, add $3$ to the score. Swap the first and the second elements and turn $1$ to $0$ on the second turn, and add $3$ to the score. The final score is $6$.

翻译中…

样例

Input #1
2
3 1
Output #1
6
InputCopy OutputCopy
Input #2
5
7 3 9 6 12
Output #2
52
InputCopy OutputCopy
题目信息
题号
1736E
时间限制
2 s
内存限制
1024 MB
标签
动态规划
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。