light oj 1227 - Boiled Eggs

1227 - Boiled Eggs
Time Limit: 0.5 second(s)Memory Limit: 32 MB

Three of the trouble-makers went to Malaysia this year. A rest house was booked for them. Unlike other rest houses, this rest house was like a normal duplex house. So, it had a kitchen. And the trouble-makers were given all the ingredients to cook, but they had to cook themselves.

None of them had any previous cooking experience, but they became very excited and planned to cook so many delicious foods! Ideas were coming from their minds like rains from clouds. So, they went to the super market and bought a lot of extra ingredients for their great recipes. For example, they bought 20 eggs. The excited trouble-makers returned to the rest house and found that the gas stove was not connected to the gas cylinder. So, they became very sad, because it was not possible for them to connect such complex thing. And so many foods were about to be rotten. But luckily, they found the microwave oven working. So, they tried to boil all the eggs using the microwave oven (may be, first time in history)! And they succeeded to boil the eggs!

Now they have n eggs and a bowl. They put some eggs in the bowl with some water. And after that they put the bowl into the oven to boil the eggs. It's risky to put more than P eggs in the bowl and the bowl can carry at most Q gm of eggs. It takes 12 minutes to boil a bowl of eggs. Now you are given the weight of the eggs in gm, and the trouble-makers have exactly 12 minutes in their hand. You have to find the maximum number of eggs they can boil without taking any risk.

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with three 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. These integers denote the weight of the eggs in gm.

Output

For each case, print the case number and the desired result.

Sample Input

Output for Sample Input

2

3 2 10

1 2 3

4 5 5

4 4 5 5

Case 1: 2

Case 2: 1

 这题也让我WA了三次……(噗…)

代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
    int t,k=1;
    int n,p,q,a[40];
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d",&n,&p,&q);
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        sort(a,a+n);
        int cnt=0,sum=0;
        for(int i=0;i<n;i++)
        {
            if(cnt<p&&sum+a[i]<=q)  //就在这儿wa的……噗
            {
                cnt++;
                sum+=a[i];
            }
            else
                break;
        }
        printf("Case %d: %d\n",k++,cnt);
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值