View Code of Problem 19

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;

int num[1000001];
int main() {
	int n,i,j;
	while(scanf("%d",&n)) {
		if(n==0) {
			break;
		}
		for(i=0; i<n; i++) {
			scanf("%d",&num[i]);
		}
		int max=-100000;
		for(i=0; i<n; i++) {
			int temp=num[i];
			for(j=i+1; j<n; j++) {
				temp=temp+num[j];
				if(temp>max) {
					max=temp;
				}
			}
		}
		printf("%d\n",max);

	}
}

Double click to view unformatted code.


Back to problem 19