View Code of Problem 19

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
 
const int inf = (1<<31)-1;
const int MAXN = 1e6+10;
 
using namespace std;
 
int main()
{
    int n;
    int a,tmp,mmax;
    while(scanf("%d",&n),n){
        mmax = -inf;
        tmp = 0;
        for(int i=0;i<n;i++){
            scanf("%d",&a);
            a += tmp;
            tmp = max(0,a);
            mmax = max(mmax,a);
        }
        cout<<mmax<<endl;
    }
    //cout << "Hello world!" << endl;
    return 0;
}

Double click to view unformatted code.


Back to problem 19