View Code of Problem 19

#include<iostream>
using namespace std;
int main()
{
	int n,i,sum,temp_sum,j,sum_zong;
	while(1){
		cin>>n;
		if(n==0)	break;
		int a[100010];
		for(i=0;i<n;++i){
			cin>>a[i];
		}
		sum_zong=0;
		for(i=0;i<n;++i){			
			temp_sum=0;
			sum=0;
			for(j=i;j<n;++j){
				temp_sum+=a[j];
				if(temp_sum>=0){
					sum+=temp_sum;
					temp_sum=0;
				}																
			}
			if(sum_zong<sum)
				sum_zong = sum;
			
		}
		cout<<sum_zong<<endl;
	}
}

Double click to view unformatted code.


Back to problem 19