From 407f1922d84531319b9c629090ba66d108313c12 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Tue, 7 Jul 2026 12:32:33 +0900 Subject: [PATCH] =?UTF-8?q?2109=20:=20=EC=88=9C=ED=9A=8C=EA=B3=B5=EC=97=B0?= =?UTF-8?q?=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week5/BOJ2109/BOJ2109_V1.cpp | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/week5/BOJ2109/BOJ2109_V1.cpp diff --git a/src/week5/BOJ2109/BOJ2109_V1.cpp b/src/week5/BOJ2109/BOJ2109_V1.cpp new file mode 100644 index 0000000..0196c9e --- /dev/null +++ b/src/week5/BOJ2109/BOJ2109_V1.cpp @@ -0,0 +1,39 @@ +#include +using namespace std; +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + int n; + cin >> n; + + vector> inp; + for (int i = 0; i < n; i++) { + int p,d; + cin >> p >> d; + inp.push_back({d,p}); + } + + sort(inp.begin(), inp.end()); + + priority_queue, greater> pq; + + for (auto [d, p] : inp) { + pq.push(p); + + if (pq.size() > d) { + pq.pop(); + } + } + int ret = 0; + while(!pq.empty()) { + ret+=pq.top(); + pq.pop(); + } + + cout << ret << '\n'; + + return 0; +} \ No newline at end of file