A13836 | Swedish Heroes
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
While playing yet another strategy game, Mans has recruited $n$ [Swedish heroes](https://www.youtube.com/watch?v=5sGOwFVUU0I), whose powers which can be represented as an array $a$ .
Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to accomplish his goal, he can pick two consecutive heroes, with powers $a_i$ and $a_{i+1}$ , remove them and insert a hero with power $-(a_i+a_{i+1})$ back in the same position.
For example if the array contains the elements $[5, 6, 7, 8]$ , he can pick $6$ and $7$ and get $[5, -(6+7), 8] = [5, -13, 8]$ .
After he will perform this operation $n-1$ times, Mans will end up having only one hero. He wants his power to be as big as possible. What's the largest possible power he can achieve?
Unfortunately, not all of those mighty heroes were created as capable as he wanted, so that he decided to do something about it. In order to accomplish his goal, he can pick two consecutive heroes, with powers $a_i$ and $a_{i+1}$ , remove them and insert a hero with power $-(a_i+a_{i+1})$ back in the same position.
For example if the array contains the elements $[5, 6, 7, 8]$ , he can pick $6$ and $7$ and get $[5, -(6+7), 8] = [5, -13, 8]$ .
After he will perform this operation $n-1$ times, Mans will end up having only one hero. He wants his power to be as big as possible. What's the largest possible power he can achieve?
输入格式
The first line contains a single integer $n$ ( $1 \le n \le 200000$ ).
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $-10^9 \le a_i \le 10^9$ ) — powers of the heroes.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $-10^9 \le a_i \le 10^9$ ) — powers of the heroes.
输出格式
Print the largest possible power he can achieve after $n-1$ operations.
输入输出样例
输入 #1
4 5 6 7 8
输出 #1
26
输入 #2
5 4 -5 9 -2 1
输出 #2
15
Suitable list of operations for the first sample:
$[5, 6, 7, 8] \rightarrow [-11, 7, 8] \rightarrow [-11, -15] \rightarrow [26]$
$[5, 6, 7, 8] \rightarrow [-11, 7, 8] \rightarrow [-11, -15] \rightarrow [26]$
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted