10684 - The jackpot

All about problems in Volume 106. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10684 - The Jackpot

Post by brianfry713 »

You can solve each input set in O(N)
Check input and AC output for thousands of problems on uDebug!
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 10684 - The Jackpot

Post by uDebug »

Replying to follow the thread.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.
ksatori
New poster
Posts: 1
Joined: Tue May 26, 2015 12:07 am

Re: 10684 - The jackpot

Post by ksatori »

Yes, I suppose this problem can be solved in O(n).
cunbidun
New poster
Posts: 3
Joined: Fri Oct 23, 2015 6:35 am

10684- WA

Post by cunbidun »

i dont understand why my code is WA

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);
    }

}
help me please
Last edited by brianfry713 on Tue Oct 27, 2015 3:23 am, edited 1 time in total.
Reason: Added code block
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10684 - The jackpot

Post by brianfry713 »

Don't read from a file.
Next time post in the existing thread.
Check input and AC output for thousands of problems on uDebug!
Post Reply

Return to “Volume 106 (10600-10699)”