View Code of Problem 19

#include <stdio.h>
int main()
{
	int n, m;
	int sum = 0;
	int max = 0;
	while(scanf("%d", &n) != EOF && n != 0)
	{
		for(int i = 0; i < n; i++)
		{
			scanf("%d", &m);
			sum += m;
			if(sum < 0)
				sum = 0;
			if(sum > max)
				max = sum;
		}
		printf("%d\n", max);
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 19