11900 - Boiled Eggs

Moderator: Board moderators

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

11900 - Boiled Eggs

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

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

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

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

thnx

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

Re: 11900

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

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

Code: Select all

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

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

Re: 11900 - Boiled Egg

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

Thanks, got ac!!

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

Re: 11900

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!

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

Re: 11900 - Boiled Egg

Check input and AC output for over 7,500 problems on uDebug!

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

Re: 11900 - Boiled Egg

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

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

Re: 11900

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: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek