HDU - 6335 - Problem D. Nothing is Impossible
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
typedef long long int LL;
int T, n, m;
LL a[111], x, y;
int main()
{
scanf("%d", &T);
while(T--){
scanf("%d%d", &n, &m);
for(int i=1;i<=n;i++){
scanf("%lld%lld", &x, &y);
a[i] = x + y;
}
sort(a+1, a+1+n);
LL ans = 0, tot = 1;
while(ans+1<=n && tot*a[ans+1]<=m){
ans ++;
tot *= a[ans];
}
printf("%lld\n", ans);
}
return 0;
}