https://www.acmicpc.net/problem/11256
C++ (그리디) 풀이
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int tc;
int main() {
cin >> tc;
while(tc--)
{
int j,N;
cin>>j>>N;
vector<int> tmp;
for(int i=0;i<N;i++)
{
int a,b;
cin>>a>>b;
tmp.push_back(a*b);
}
sort(tmp.begin(),tmp.end(),greater<int>());
int answer=0;
int total=0;
for(auto a : tmp)
{
total+=a;
answer++;
if(total>=j) {
cout<<answer<<'\n';
break;
}
}
}
}