View Code of Problem 19

#include <stdio.h>
using namespace std;

const int MAXN = 1e6;
int arr[MAXN];
int main(){

	int n;
	int sum;
	while( ~scanf("%d", &n) && n != 0 ){
		
		for( int i=0; i<n; i++ ){
			 scanf("%d", &arr[i]);
		}
		int max = arr[0];
		for( int i=0; i<n; i++ ){
			sum =0;
			for( int j=i; j<n; j++ ){
				sum += arr[j];
				if( sum > max ){
					max = sum;
				}
			}
		}
		printf("%d\n", max );
	}

	return 0;
	
}

Double click to view unformatted code.


Back to problem 19