hdu-6335 Nothing is Impossible

题目链接

Problem Description

m students, including Kazari, will take an exam tomorrow.
The paper consists of exactly n problems, the i-th problem contains ai correct answers and bi incorrect answers, i.e. the i-th problem contains ai+bi candidates in total.
Each student should choose exactly one candidate as answer for each problem. If the answer to a certain problem is correct, then the student will get one point. The student who gets the most points wins.
Students only know the structure of the paper, but they are able to talk with each other during the exam. They decide to choose a subset S of all n problems, and they will only be able to submit answers on these problems.
They want to know the maximum size of S that the winner among them will solve all the problems in S if they take the optimal strategy.


For sample 1, students can choose S={1},and we need at least 4 students to guarantee the winner solve the only problem.

For sample 2, students can choose S={1,2,3}, and we need at least 24 students to guarantee the winner solve these three problems, but if |S|=4, we need at least 96students, which is more than 50.

Input

The first line of the input contains an integer T (1≤T≤100) denoting the number of test cases.
Each test case starts with two integers n,m (1≤n≤100,1≤m≤109), denoting the number of problems and the number of students. Each of next n lines contains two integers ai,bi (1≤bi≤100,ai=1), indicating the number of correct answers and the number of incorrect answers of the i-th problem.

Output

For each test case, print an integer denoting the maximum size of S.

Sample Input

2

3 5

1 3

1 3

1 3

5 50

1 1

1 3

1 2

1 3

1 5

Sample Output

1

3

 题目大意:

T组测试样例,n道题,m个人;接下来是n道题的正确答案和错误答案的个数(前面是正确的后面是错误的);错误的人不能在参加后面的题;输出m个人最保守估计能出来几道题;

解题思路:

最保守估计也就是在错误的答案个数上加一(比如:正确答案4个,错误答案是5个,那就只需要是6个人中对一个就可以了,这才是最保守估计),用总人数去除以错误答案个数加一;忽略小数点后的数字;一定要注意,要对题目错误答案的个数进行排序,这样才可以做出更多的题(先做错误答案少的题目);

代码:

#include<cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
struct timu
{
    int a,b,c;
}a[10000];
bool cmp(timu x,timu y)//自定义排序规则
{
    return x.c < y.c;
}
int main()
{
    int n,m,T,x,i,sum;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d %d",&n,&m);
        sum=0;
        for(i=1;i<=n;i++)
        {
            scanf("%d %d",&a[i].a,&a[i].b);
            a[i].c=a[i].b+1;
        }
        sort(a+1,a+n+1,cmp);
        for(i=1;i<=n;i++)
        {
            if(m>a[i].b)
            {
                m=m/a[i].c;
                sum++;
            }
            else
                break;

        }
        printf("%d\n",sum);
    }

}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值