View Code of Problem 19

#include<bits/stdc++.h>
using namespace std;
#define ma 1000001 
int a[ma];                                 
int main(){      
	 int n,max = -100000;
	 while(cin>>n){
	 	if(n==0)break;
	 	int sum = 0,k = 0,op;	
		for(int i = 1;i<=n;i++) cin>>a[i];
	 	for(int i = 1;i<=n;i++){
	 		k = a[i];
			for(int j = i + 1;j<=n;j++){
	 			sum = k + a[j];
	 			if(sum > max) max = sum;
	 				k = sum;
			}
			sum = 0;
		}
	 	cout<<max<<endl;
	 	
	 	
	 	
	 	
	 }
	return 0;
}

Double click to view unformatted code.


Back to problem 19