思路:将二元组以y为第以关键字排序, 从前向后乘以(y+1)直到超过总人数。
代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 100
struct Pair{
int x,y;
Pair(){}
Pair(int xx,int yy) {
x=xx,y=yy;
}
bool operator < (const Pair& oth) const {
return y<oth.y;
}
};
int n,m;
Pair a[maxn+5];
int main() {
int T;
scanf("%d",&T);
while(T--) {
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) {
int x,y;
scanf("%d%d",&x,&y);
a[i]=(Pair){x,y};
}
sort(a+1,a+n+1);
ll ans=1,s=0;
for(int i=1;i<=n;i++) {
ans*=(1+a[i].y);
if(ans>m) {
break;
}
s=i;
}
printf("%d\n",s);
}
return 0;
}