1. 程式人生 > >hdu-6335 Nothing is Impossible

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

}