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