问题 3755 --偶数位最大和(完善程序)

3755: 偶数位最大和(完善程序)★★★

时间限制: 1 Sec  内存限制: 128 MB
提交: 9  解决: 7
[提交][状态][命题人:]

题目描述

这里有一个长度为n的序列a{a0 a1 a2...an-1}。你可以翻转且至多翻转一次a中的一段子串。试问翻转后的a序列中偶数位的最大和是多少。

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
typedef long long ll;
#define M 1000005
 
int A[M];
 
int main(){
    int t,n;scanf("%d",&t);
    ll as1,as2,a,b;
    while(t--){
    	scanf("%d",&n);
        for(int i=0;i<n;++i) scanf("%d",&A[i]);
        a=0;  as1=0;
        b=A[0];
        for(int i=2;i<n;i+=2){
            if(a + A[i-1] - A[i] <0) a=0;
            else a += A[i-1] - A[i], as1= max(as1, a);
            _____(1)______;
        }
        a=0; as2=0;
        for(______(2)_______){
            if(______(3)______) a=0;
            else ______(4)______ 
        }
        printf("%lld\n",______(5)_______);
    }
    return 0;
}

输入

4

8

1 7 3 4 7 6 2 9

5

1 2 1 2 1

10

7 8 4 5 7 6 8 9 7 3

4

3 1 2 1

输出

26

5

37

5

提示

来源

[提交][状态]