10684 - The jackpot
Moderator: Board moderators
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10684 - The Jackpot
You can solve each input set in O(N)
Check input and AC output for thousands of problems on uDebug!
Re: 10684 - The jackpot
Yes, I suppose this problem can be solved in O(n).
10684- WA
i dont understand why my code is WA
help me please
Code: Select all
#include<stdio.h>
#include<string.h>
int main(){
freopen("10684uva.txt","r",stdin);
long int a[1000],n,i=1,t[10000],max=-999999,j,cc;
t[0]=0;
while(scanf("%lld",&n)==1)
{
if(n==0)break;
for(i=1;i<=n;i++){
scanf("%d",&a[i]);
t[i]=t[i-1]+a[i];
}
/*for(i=1;i<=n;i++)
printf("%d ",t[i]);*/
max=-1;
if(n!=1)
{
for(i=2;i<=n;i++)
for(j=0;j<i;j++)
{
cc=t[i]-t[j];
if(cc>max) max=cc;
}
if(max>0) printf("The maximum winning streak is %d.\n",max);
else printf("Losing streak.\n");
max=-1;
}
else if(a[1]>0) printf("The maximum winning streak is %d.\n",max);
else printf("Losing streak.\n");
memset(a,0,n);
memset(t,0,n);
}
}
Last edited by brianfry713 on Tue Oct 27, 2015 3:23 am, edited 1 time in total.
Reason: Added code block
Reason: Added code block
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10684 - The jackpot
Don't read from a file.
Next time post in the existing thread.
Next time post in the existing thread.
Check input and AC output for thousands of problems on uDebug!