View Code of Problem 19

#include<iostream>
using namespace std;
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		if(n==0)break;
		int a[n],max=-99999;
		
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int i=0;i<n;i++){
			int sum=0;
			for(int j=i;j<n;j++){
				sum+=a[j];
				if(sum>max){
				max=sum;
			}
			}
			
		}
		cout<<max<<endl;
		
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 19