Problem Type : Max 1D range sum
Code :
#include<stdio.h>
#define mx 10003
int main()
{
int test,i,j;
while(scanf("%d",&test)==1)
{
long int max_arr,sum;
max_arr = 0;
sum = 0;
if(test==0)
break;
for(i=0; i<test; i++)
{
scanf("%d",&j);
sum+=j;
if(sum>max_arr)
{
max_arr = sum;
}
if(sum<0)
{
sum=0;
}
}
if(max_arr)
{
printf("The maximum winning streak is %ld.\n",max_arr);
}
else
{
printf("Losing streak.\n");
}
}
return 0;
}
No comments:
Post a Comment