Page **1** of **1**

### 11900 - Boiled Eggs

Posted: **Sun Apr 22, 2012 5:09 pm**

by **Hasselli**

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

### Re: 11900

Posted: **Mon Apr 23, 2012 11:31 pm**

by **brianfry713**

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.

### Re: 11900

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

by **Hasselli**

AC

### Re: 11900

Posted: **Tue Apr 24, 2012 11:47 pm**

by **brianfry713**

What if sum==q?

What if n<p?

### Re: 11900

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

by **Hasselli**

thnx

### Re: 11900

Posted: **Thu Jun 14, 2012 8:30 am**

by **uvasarker**

I am getting WA please help me

### Re: 11900

Posted: **Thu Jun 14, 2012 10:10 pm**

by **brianfry713**

Input:

Code: Select all

```
3
3 2 10
1 2 3
4 5 5
4 4 5 5
1 4 30
1
```

AC Output:

### 11900 - Boiled Egg

Posted: **Sat Feb 23, 2013 2:21 pm**

by **shondhi**

### Re: 11900 - Boiled Egg

Posted: **Mon Feb 25, 2013 3:08 am**

by **sohel**

You are assuming that** p** is not greater than **n**.

### Re: 11900 - Boiled Egg

Posted: **Fri Apr 12, 2013 5:42 pm**

by **shondhi**

Thanks, got ac!!

### Re: 11900

Posted: **Thu Jun 19, 2014 12:36 pm**

by **uDebug**

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**

by **uDebug**

Replying to follow the thread.

### Re: 11900 - Boiled Egg

Posted: **Sun Aug 10, 2014 2:38 pm**

by **axelblaze**

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

### Re: 11900

Posted: **Sun Aug 10, 2014 7:24 pm**

by **lighted**

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**

by **lighted**

Check input in this thread, your program gives wrong answers.

http://acm.uva.es/board/viewtopic.php?f ... 0f#p369606