[洛谷P2642]双子序列最大和

题目←

这种题还交上那么多遍大概我确实是菜……
甚至一开始读的题意都是错的……但是拿错的题意打还过了样例了……真是……

#include
#include
#include
#define LL long long
#define INF 2147483647
using namespace std;
const int MAXN = 1000000 + 50;
LL v[MAXN],minx[MAXN],ans = -INF,w[MAXN],hminx[MAXN];
int n,a[MAXN];
LL sum1[MAXN],sum2[MAXN];
int main(){
    scanf("%d",&n);
    for(int i = 1;i <= n;i ++){
        scanf("%d",&a[i]);
        v[i] = v[i - 1] + a[i];
        minx[i] = min(minx[i - 1],v[i]);
    }
    sum1[1] = v[1];
    for(int i = 1;i <= n;i ++){
        if(i != 1)sum1[i] = max(sum1[i - 1],v[i] - minx[i - 1]);
        w[n - i + 1] = w[n - i + 1 + 1] + a[n - i + 1];
        hminx[n - i + 1] = min(hminx[n - i + 1 + 1],w[n - i + 1]);
    }
    sum2[n] = w[n];
    for(int i = n - 1;i >= 1;i --){
        sum2[i] = max(sum2[i + 1],w[i] - hminx[i + 1]);
    }
    for(int i = 2;i < n;i ++){
        ans = max(ans,sum1[i - 1] + sum2[i + 1]);
    }
    printf("%lld",ans);
    return 0;
}

Tips:
读清题目
交之前先检查一遍代码

你可能感兴趣的:(错题记录,模拟)