CF1421E.Swedish Heroes

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

While playing yet another strategy game, Mans has recruited nn Swedish heroes, whose powers which can be represented as an array aa .

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 aia_i and ai+1a_{i+1} , remove them and insert a hero with power (ai+ai+1)-(a_i+a_{i+1}) back in the same position.

For example if the array contains the elements [5,6,7,8][5, 6, 7, 8] , he can pick 66 and 77 and get [5,(6+7),8]=[5,13,8][5, -(6+7), 8] = [5, -13, 8] .

After he will perform this operation n1n-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 nn ( 1n2000001 \le n \le 200000 ).

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 109ai109-10^9 \le a_i \le 10^9 ) — powers of the heroes.

输出格式

Print the largest possible power he can achieve after n1n-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][11,7,8][11,15][26][5, 6, 7, 8] \rightarrow [-11, 7, 8] \rightarrow [-11, -15] \rightarrow [26]

首页