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

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun » Mon Jan 02, 2006 4:47 pm

Declare check[][] and money[] globally or as static in main().

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Post by helloneo » Mon Jan 02, 2006 5:00 pm

the array check[][] is too big..~

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

CE...

Post by Obaida » Sun Mar 23, 2008 8:12 am

Is there any reason to have CE...! This is crazy....
Any one could debug my program and suggest me that it's ok or not...

Code: Select all

Thank you mf I was wrong in thinking..
AC.... :wink: 
Last edited by Obaida on Thu Mar 27, 2008 11:59 am, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

WA...

Post by Obaida » Sun Mar 23, 2008 8:30 am

Ok... I traced why CE... I was using i in both loop... But now it is getting WA.... Help me...[/code]
try_try_try_try_&&&_try@try.com
This may be the address of success.

rajib_sust
New poster
Posts: 16
Joined: Sun Mar 02, 2008 10:34 am
Location: SUST , Sylhet, Bangladesh

Re: 10684 - The Jackpot

Post by rajib_sust » Fri Aug 29, 2008 10:40 am

Code: Select all

he can identify patterns of consecutive wins and elaborate a win-win strategy.
A bet is an amount of money and is either winning (and this is recorded as a positive value). 
i am not understand this two line of code. what do u mean by win win strategy.

rajib
sust
life is beautiful like coding

Skt
New poster
Posts: 5
Joined: Wed Oct 29, 2008 2:55 pm

Re: 10684 - The Jackpot

Post by Skt » Tue Sep 15, 2009 7:30 pm

well this is how my code looks like if i have found it to be coorect its the maximum sum and used dp for it can any one plz tell my errors or provide me with test case which would help me realize my error

long long i,j,arr[1001];
while(cin>>n && n!=0)
{
long long s[1001] = {0};
FOR(i,1,n+1)
cin>>arr;
s[0] = 0;
FOR(i,1,n+1)
s = MAX(s[i-1]+arr,arr);
if(s[i-1]>0)
cout<<"The maximum winning streak is "<<s[i-1]<<"."<<endl;
else
cout<<"Losing streak."<<endl;
}
** MAX & FOR are simple macros that i have used

mathgirl
New poster
Posts: 36
Joined: Tue Apr 24, 2012 6:20 pm

Re: 10684 - The Jackpot

Post by mathgirl » Sat May 19, 2012 12:25 pm

Is this problem maximum consecutive sum or maximum sum ? I have tried both, but getting WA.

For example,
5 5 -1 5 5
Is the answer 10 or 19 ?

Code: Select all

#include<stdio.h>
#include<vector>

using namespace std;

int main()
{
	int n,re;
	re = scanf("%d",&n);
	while(n)
	{
		vector<int> input;
		int a;
		for(int j=1;j<=n;j++)
		{
			scanf("%ld",&a);
			input.push_back(a);
		}

		int sum = 0,maxs = 0;
		int i = 0,j;
		while(i<input.size())
		{
			sum = 0;
			j = i;
			while(j<input.size())
			{
				sum = sum + input[j];
				j++;
				maxs = max(sum,maxs);
			}
			i++;
		}

		if(maxs>0)
			printf("The maximum winning streak is %d.\n",maxs);
		else
			printf("Losing streak.\n");

		re = scanf("%d",&n);
		
	}

	return 0;
}

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

Re: 10684 - The Jackpot

Post by brianfry713 » Tue May 22, 2012 2:47 am

maximum possible gain out of a sequence of consecutive bets.

19.

Use %d when reading an int in scanf.
Check input and AC output for thousands of problems on uDebug!

tamimcsedu19
New poster
Posts: 3
Joined: Fri Mar 01, 2013 6:17 pm

Re: 10684 - The Jackpot

Post by tamimcsedu19 » Sat Apr 20, 2013 7:21 pm

Why WA, where am I wrong?

Code: Select all

#include <stdio.h>
#include <iostream>
#include <iterator>
using namespace std;
int main()
{
    int n;
    while(scanf("%d",&n)&&n!=0){
    std::istream_iterator<int> int_it(cin),end;
    int sum=*int_it++;
    for(int i=2;i<n;++i)
    {
        sum+=*int_it++;
        if(sum<0)
        sum=0;
    }
    sum+=*int_it;
    if(sum>0)
    printf("The maximum winning streak is %d.\n",sum);
    else
    printf("Losing streak.\n");
    }

}

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

Re: 10684 - The Jackpot

Post by brianfry713 » Mon Apr 22, 2013 11:44 pm

Try input:
1
1
0
Check input and AC output for thousands of problems on uDebug!

MauriWilde
New poster
Posts: 14
Joined: Sun Jan 20, 2013 1:58 am

Re: 10684 - The Jackpot

Post by MauriWilde » Sat Jun 22, 2013 4:38 am

Hi,

today I made this problem and I found something interesting.

I sent my code and while it was in queue I realized that my code failed for this case:

1
1
0

So I sent it again, but with the correction.

The funny thing is that when I checked I had the two submissions accepted.

The firstone's output was:
Losing streak.
and the second's:
The maximum winning streak is 1.
How could be this possible?
Last edited by MauriWilde on Sun Jun 01, 2014 9:28 pm, edited 1 time in total.

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

Re: 10684 - The Jackpot

Post by brianfry713 » Sat Jun 22, 2013 6:55 am

The second is correct. The judge can't test all possible inputs, so whatever was wrong with your code isn't tested by the judge's I/O.
Check input and AC output for thousands of problems on uDebug!

ashdboss
New poster
Posts: 16
Joined: Fri May 17, 2013 8:59 am

Re: 10684 - The Jackpot

Post by ashdboss » Wed Aug 14, 2013 3:17 pm

Getting wrong answer.Need help

Code: Select all

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<stdlib.h>
#include <queue>
#include <stack>
#include<string>
#include<list>
#include<map>
#include<math.h>
#include<algorithm>

using namespace std;
int main()
{
	int n,x;
	long long sum,max;
	while(scanf("%d",&n) == 1 && n)
	{
		max = -1;
		sum = 0;
		while(n--)
		{
		scanf("%d",&x);
		if(x < 0)
			{
			if(max < sum)
				max = sum;
			sum =0;
			}
		else
			sum = sum + x;
		}
		if(max < sum)
			max = sum;
		
		if(max > 0)
			printf("The maximum winning streak is %lld.\n",max);
		else
			printf("Losing streak.\n");
	}
	return 0;
}

t.tahasin
New poster
Posts: 38
Joined: Tue May 28, 2013 11:21 pm

Re: 10684 - The Jackpot

Post by t.tahasin » Wed Aug 14, 2013 3:28 pm

try this
input:
5
12 -4
-3 4
9
0
output:
The maximum winning streak is 18.

Scorvus
New poster
Posts: 4
Joined: Sun Apr 21, 2013 8:19 pm

Re: 10684 - The Jackpot

Post by Scorvus » Thu Sep 26, 2013 5:14 pm

I got TLE with this code but when I tried n=10000 it work faster than 3s.
Please help me improve my code.

Code: Select all

#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int sum,n[10005],tmp[10005],big;
	while(1)
		{
		scanf("%d",&sum);
		if(sum==0)
		break;
		for(int i=0;i<sum;i++)
		{
			scanf("%d",&n[i]);
			tmp[i]=n[i];
		}
		big=*max_element(n,n+sum);
		for(int i=1;i<sum;i++)
		{
			for(int j=0;j<sum-i;j++)
			{
				tmp[j]+=n[j+i];
				if(big<tmp[j])
				big=tmp[j];
			}
			
		}
		if(big<1)
			printf("Losing streak.\n");
		else
			printf("The maximum winning streak is %d.\n",big);
	}
}

Post Reply

Return to “Volume 106 (10600-10699)”