必威体育Betway必威体育官网
当前位置:首页 > IT技术

Nothing is Impossible

时间:2019-07-13 14:41:03来源:IT技术作者:seo实验室小编阅读:78次「手机版」
 

nothing is impossible

Problem D. nothing is impossible

Time limit: 2000/1000 MS (java/Others)    Memory Limit: 262144/262144 K (Java/Others)

Total Submission(s): 2628    Accepted Submission(s): 804

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 96 students, 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


题解:

如果仅有 1 道题,至少有一个人做对这题需要有 错误答案个数 + 1 个人。

那么容易发现在每道题正确答案只有一个的情况下,如果 nn 道题中存在 ss 道题,使得学生人数 mm 不少于每道题 错误答案个数 + 1 相乘的结果,那么一定有人能够得到 ss 分。故我们将题目按错误答案个数从小到大排序,找到最大的 pp 满足 \prod_{i \le p} {(b_i + 1)} \le m∏​i≤p​​(b​i​​+1)≤m 就是答案。

#include <bits/stdc++.h>

using namespace std;

int main(){
	int t,n,c[500];
	scanf("%d",&t);
	long long int m;
	while(t--){
		scanf("%d %lld",&n,&m);	
		for(int i=0;i<n;i++){
			int a,b;
			scanf("%d %d",&a,&b);
			c[i] = a+b;
		}	
		sort(c,c+n);
		int i = 0;
		long long int k = 1;
		for(i=0;i<n;i++){
			k *= c[i];
			if(k > m)
				break;
		}
		printf("%d\n",i);
	}

}

相关阅读

分享到:

栏目导航

推荐阅读

热门阅读