Codeforces Round 508 (Div. 2)
D
Slime
Codeforces
1800
原题
← CE →
翻译中…

There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.

翻译中…

Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists).

翻译中…

When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears, and the value of the remaining slime changes to $x - y$.

翻译中…

The slimes will eat each other until there is only one slime left.

翻译中…

Find the maximum possible value of the last slime.

翻译中…

Input

翻译中…

The first line of the input contains an integer $n$ ($1 \le n \le 500\,000$) denoting the number of slimes.

翻译中…

The next line contains $n$ integers $a_i$ ($-10^9 \le a_i \le 10^9$), where $a_i$ is the value of $i$-th slime.

翻译中…

Output

翻译中…

Print an only integer — the maximum possible value of the last slime.

翻译中…

Note

翻译中…

In the first example, a possible way of getting the last slime with value $4$ is:

翻译中…
  • Second slime eats the third slime, the row now contains slimes $2, -1, 1$
  • Second slime eats the third slime, the row now contains slimes $2, -2$
  • First slime eats the second slime, the row now contains $4$
翻译中…

In the second example, the first slime can keep eating slimes to its right to end up with a value of $4$.

翻译中…

样例

Input #1
4
2 1 2 1
Output #1
4
InputCopy OutputCopy
Input #2
5
0 -1 -1 -1 -1
Output #2
4
InputCopy OutputCopy
题目信息
题号
1038D
时间限制
2 s
内存限制
256 MB
标签
动态规划
贪心
模拟

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