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 b;
	int a[10000001];
	int c[10000001];
	while (scanf("%d", &n) != EOF) {
		if (n == 0)
			break;
		for (int i = 1; i <= n; i++) {
			scanf("%d", &b);
			a[i] = b;
		}
		for (int i = 1; i <= n; i++) {
			if (i == 1)
				c[i] = a[i];
			c[i] = max(a[i], a[i] + c[i - 1]);
		};
		for (int i = 1; i < n; i++)
			if (c[i] > c[i + 1])
				c[i + 1] = c[i];
		    
		printf("%d", c[n]);
       
	}
}

Double click to view unformatted code.


Back to problem 19