View Code of Problem 19

#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int a[1010];
	int n;
	while(scanf("%d",&n)!=EOF&&n!=0)
	{		
		for(int i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
		}
		int maxSum=a[0];
		for(int i=1;i<n;i++)
		{
      		if(a[i-1]>0)
			{
				a[i]+=a[i-1];
			}
        maxSum = max(a[i], maxSum);
		}
		printf("%d\n",maxSum);
	}
	return 0;
} 

Double click to view unformatted code.


Back to problem 19