线性dp

代码:

#include<iostream>
#include<limits.h>
using namespace std;
const int MAX=1e6+10;
typedef long long ll;
ll f[MAX],a[MAX];
int main(){
    int n;
    while(~scanf("%d",&n)){
        for(int i=1;i<=n;++i)    scanf("%lld",&a[i]);
        f[1]=a[1];
        ll maxx=f[1];
        for(int i=2;i<=n;++i){
            if(f[i-1]>0) f[i]=f[i-1]+a[i];
            else f[i]=a[i];
            maxx=max(f[i],maxx);
        }
        printf("%lld\n",maxx);
    }
    return 0;
}