View Code of Problem 19

#include<stdio.h>
#include<math.h>
#include<string.h>
int max(int a, int b)
{
	if (a > b) return a;
	return b;
}
int main()
{
	int n;
	int m;
	int b;
	int a[1000000];
	int c;
	while (scanf("%d", &n) != EOF) {
		if (n == 0)
			break;
		for (int i = 0; i < n; i++) {
			scanf("%d", &b);
			a[i] = b;
		}
		m = a[0];

		for (int i = 0; i < n; i++) {
			if (i == 0)
				c = a[i];
			c = max(a[i], a[i] + c);
			if (c > m)
				m = c;
		};
		printf("%d", m);


	}
	return 0;
}

Double click to view unformatted code.


Back to problem 19