Search
Duplicate
📗

사탕

주차
문제번호
11256
언어
C++
티어
실버
유형
그리디
정렬
nj_Blog
nj_상태
이해도
100%
풀이
사람
이해도 2
13 more properties

문제접근

가로 * 세로가 높은 순으로 정렬하여 상위 박스부터 우선적으로 사용해보면서 다 담을 수 있는지 확인

놓쳤던 부분

코드

2024 KB

0 ms

#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(void) { int t; int j, n; int r, c; ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> t; for (int test_case = 0; test_case < t; test_case++) { vector<int> box; cin >> j >> n; for (int i = 0; i < n; i++) { cin >> r >> c; box.push_back(r * c); } sort(box.begin(), box.end(), greater<>()); int total = 0; int idx = 0; while (total < j) { total += box[idx]; idx++; } cout << idx << "\n"; } return (0); }
C++
복사