PTA 最大子列和问题

https://pintia.cn/problem-sets/15/problems/709

#include<iostream>
#include<cstdio>
using namespace std;

int main(){
    int n,x;
    long long s=0,t=0;
    scanf("%d",&n);
    while(n--){
        scanf("%d",&x);
        t+=x;
        if(t>s)
            s=t;
        if(t<0)
            t=0;
    }
    printf("%lld\n",s);
return 0;
}

猜你喜欢

转载自blog.csdn.net/yimo_180227/article/details/81736980