반응형
-문제
-코드
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
int t, j, n, r, c, res = 0;
scanf("%d", &t);
vector<int> a;
for (int i = 0; i < t; i++)
{
scanf("%d %d", &j, &n);
a.clear();
res = 0;
for (int i = 0; i < n; i++)
{
scanf("%d %d", &r, &c);
a.push_back(r*c);
}
sort(a.rbegin(), a.rend());
for (int i = 0; i < n; i++)
{
j -= a[i];
res++;
if (j <= 0) break;
}
printf("%d\n", res);
}
return 0;
}
반응형
'이론 > 코딩테스트' 카테고리의 다른 글
[백준] 1590번 캠프가는 영식 (그리디 알고리즘) (0) | 2022.08.25 |
---|---|
[백준] 1246번 온라인 판매 (그리디 알고리즘) (0) | 2022.08.24 |
[백준] 9237번 이장님 초대 (그리디 알고리즘) (0) | 2022.08.21 |
[백분] 6550번 부분 문자열 (그리디 알고리즘) (0) | 2022.08.21 |
[백준] 2828번 사과 담기 게임 (그리디 알고리즘) (0) | 2022.08.20 |