11900 - Boiled Eggs

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

Moderator: Board moderators

Post Reply
Hasselli
New poster
Posts: 22
Joined: Mon Apr 16, 2012 8:08 pm
Contact:

11900 - Boiled Eggs

Post by Hasselli » Sun Apr 22, 2012 5:09 pm

Why this is wrong?

Code: Select all

#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int t;
	cin >> t;
	for (int tt = 0; tt < t; tt++){
		int n, p, q;
		cin >> n >> p >> q;
		int a[31];
		for (int i = 1; i <= n; i++)
			cin >> a[i];
		sort(a, a + n);
		int mx;
		if (p < q)
			mx = p;
		else
			mx = q;
		int sum = 0;
		for (int i = 1; i <= mx; i++){
			sum += a[i];
			if (sum >= q)
				if (i - 1 < mx)
					mx = i - 1;
		}
		cout << "Case " << tt + 1 << ": " << mx << endl;
	}
}

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

Re: 11900

Post by brianfry713 » Mon Apr 23, 2012 11:31 pm

sort starts at a[0], your input starts at a[1], but you don't need to sort as the problem statement says that the eggs are already sorted.

You should also consider P and Q separately and not try to combine them.
Check input and AC output for thousands of problems on uDebug!

Hasselli
New poster
Posts: 22
Joined: Mon Apr 16, 2012 8:08 pm
Contact:

Re: 11900

Post by Hasselli » Tue Apr 24, 2012 6:41 pm

AC
Last edited by Hasselli on Wed Apr 25, 2012 6:06 pm, edited 1 time in total.

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

Re: 11900

Post by brianfry713 » Tue Apr 24, 2012 11:47 pm

What if sum==q?
What if n<p?
Check input and AC output for thousands of problems on uDebug!

Hasselli
New poster
Posts: 22
Joined: Mon Apr 16, 2012 8:08 pm
Contact:

Re: 11900

Post by Hasselli » Wed Apr 25, 2012 6:07 pm

thnx

uvasarker
Learning poster
Posts: 96
Joined: Tue Jul 19, 2011 12:19 pm
Location: Dhaka, Bangladesh
Contact:

Re: 11900

Post by uvasarker » Thu Jun 14, 2012 8:30 am

I am getting WA please help me

Code: Select all

/* Removed */
Last edited by uvasarker on Sun Jun 17, 2012 8:28 am, edited 1 time in total.

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

Re: 11900

Post by brianfry713 » Thu Jun 14, 2012 10:10 pm

Input:

Code: Select all

3
3 2 10
1 2 3
4 5 5
4 4 5 5
1 4 30
1
AC Output:

Code: Select all

Case 1: 2
Case 2: 1
Case 3: 1
Check input and AC output for thousands of problems on uDebug!

shondhi
New poster
Posts: 25
Joined: Tue Oct 02, 2012 5:24 pm
Location: Chittagong
Contact:

11900 - Boiled Egg

Post by shondhi » Sat Feb 23, 2013 2:21 pm

Code: Select all

 Got AC 
Last edited by shondhi on Fri Apr 12, 2013 5:41 pm, edited 1 time in total.

User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 11900 - Boiled Egg

Post by sohel » Mon Feb 25, 2013 3:08 am

You are assuming that p is not greater than n.

shondhi
New poster
Posts: 25
Joined: Tue Oct 02, 2012 5:24 pm
Location: Chittagong
Contact:

Re: 11900 - Boiled Egg

Post by shondhi » Fri Apr 12, 2013 5:42 pm

Thanks, got ac!!

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11900

Post by uDebug » Thu Jun 19, 2014 12:36 pm

Here's some test cases I found useful during testing / debugging.

Input:

Code: Select all

4
5 5 100
20 20 20 20 20
10 1 45
1 2 3 4 5 6 7 8 9 9
1 10 60
30 45 60
3 100 29
45 46 47
AC Output:

Code: Select all

Case 1: 5
Case 2: 1
Case 3: 1
Case 4: 0
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11900 - Boiled Egg

Post by uDebug » Thu Jun 19, 2014 12:37 pm

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.

axelblaze
New poster
Posts: 34
Joined: Mon Jun 23, 2014 7:45 pm

Re: 11900 - Boiled Egg

Post by axelblaze » Sun Aug 10, 2014 2:38 pm

I'm constantly getting WA. I checked all possible inputs. plz help...
here's my code:

Code: Select all

#include <stdio.h>
int main()
{
    int test,c,k,sum,n,p,l,q,i,w[100],j,t;
    scanf(" %d",&test);
   for(l=1;l<=test;l++)
    {
        c=0;
        sum=0;
        scanf("%d %d %d",&n,&p,&q);
        for(i=0;i<n;i++)
        {
            scanf("%d",&w[i]);
        }
        for(k=0;k<p;k++)
        {
            sum=sum+w[k];
            if(sum>q)
            {
                break;
            }
            c++;
        }
        printf("Case %d: %d\n",l,c);
    }
    return 0;
}
thanks in advance.. :)

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 11900

Post by lighted » Sun Aug 10, 2014 7:24 pm

Each case starts with 3 integers n (1 ? n ? 30), P (1 ? P ? 30) and Q (1 ? Q ? 30). The next line contains n positive integers (not greater than 10) in non-descending order
According to problem description input is not correct.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 11900 - Boiled Egg

Post by lighted » Sun Aug 10, 2014 7:26 pm

Check input in this thread, your program gives wrong answers.
http://acm.uva.es/board/viewtopic.php?f ... 0f#p369606
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Post Reply

Return to “Volume 119 (11900-11999)”