From ee5a635ae99166f73dd2629e476c2db7eb54ebf9 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Thu, 9 Jul 2026 12:03:13 +0900 Subject: [PATCH] =?UTF-8?q?[BOJ=201202]=20=EB=B3=B4=EC=84=9D=20=EB=8F=84?= =?UTF-8?q?=EB=91=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week5/BOJ1202/BOJ1202_V1.cpp | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/week5/BOJ1202/BOJ1202_V1.cpp diff --git a/src/week5/BOJ1202/BOJ1202_V1.cpp b/src/week5/BOJ1202/BOJ1202_V1.cpp new file mode 100644 index 0000000..8d221e2 --- /dev/null +++ b/src/week5/BOJ1202/BOJ1202_V1.cpp @@ -0,0 +1,48 @@ +#include +using namespace std; +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(nullptr); + cout.tie(nullptr); + + int N,K; + vector bag; + vector> treasure; + + cin >> N >> K; + + for (int i=0; i> w >> v; + treasure.push_back({w,v}); + } + + for (int i=0; i> w; + bag.push_back(w); + } + + sort(bag.begin(), bag.end()); + sort(treasure.begin(), treasure.end()); + + priority_queue pq; + long long int ret = 0; + int idx = 0; + for (int next_bag : bag) { + while (idx < N && treasure[idx].first <= next_bag) { + pq.push(treasure[idx].second); + idx++; + } + + if (!pq.empty()) { + ret += pq.top(); + pq.pop(); + } + } + + cout << ret << '\n'; + + return 0; +} \ No newline at end of file