From da19ede63d257110d204a18cc28a708e27f3d6f5 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Tue, 7 Jul 2026 16:01:50 +0900 Subject: [PATCH] =?UTF-8?q?1781=20:=20=EC=BB=B5=EB=9D=BC=EB=A9=B4=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week5/BOJ1781/BOJ1781_V1.cpp | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/week5/BOJ1781/BOJ1781_V1.cpp diff --git a/src/week5/BOJ1781/BOJ1781_V1.cpp b/src/week5/BOJ1781/BOJ1781_V1.cpp new file mode 100644 index 0000000..2e79abf --- /dev/null +++ b/src/week5/BOJ1781/BOJ1781_V1.cpp @@ -0,0 +1,37 @@ +#include +using namespace std; +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(nullptr); + cout.tie(nullptr); + + vector> inp; + int n; + cin >> n; + for (int i=0; i> d >> c; + inp.push_back({d,c}); + } + + 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