Page 1 of 1

### 11900 - Boiled Eggs

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

### Re: 11900

Posted: Mon Apr 23, 2012 11:31 pm
sort starts at a, your input starts at a, 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.

### Re: 11900

Posted: Tue Apr 24, 2012 6:41 pm
AC

### Re: 11900

Posted: Tue Apr 24, 2012 11:47 pm
What if sum==q?
What if n<p?

### Re: 11900

Posted: Wed Apr 25, 2012 6:07 pm
thnx

### Re: 11900

Posted: Thu Jun 14, 2012 8:30 am

Code: Select all

``````/* Removed */
``````

### Re: 11900

Posted: 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``````

### 11900 - Boiled Egg

Posted: Sat Feb 23, 2013 2:21 pm

Code: Select all

`` Got AC ``

### Re: 11900 - Boiled Egg

Posted: Mon Feb 25, 2013 3:08 am
You are assuming that p is not greater than n.

### Re: 11900 - Boiled Egg

Posted: Fri Apr 12, 2013 5:42 pm
Thanks, got ac!!

### Re: 11900

Posted: 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
``````

### Re: 11900 - Boiled Egg

Posted: Thu Jun 19, 2014 12:37 pm

### Re: 11900 - Boiled Egg

Posted: 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,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.. ### Re: 11900

Posted: 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.

### Re: 11900 - Boiled Egg

Posted: Sun Aug 10, 2014 7:26 pm