Skip to content

Commit

Permalink
24-04-11 보석 도둑
Browse files Browse the repository at this point in the history
  • Loading branch information
makehard23 committed Apr 11, 2024
1 parent 6397334 commit af6a387
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 85 deletions.
85 changes: 0 additions & 85 deletions yuyu0830/탐색/12851.cpp

This file was deleted.

56 changes: 56 additions & 0 deletions yuyu0830/그리디/1202.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<int, int> ii;

#define fastio cin.tie(NULL); cin.sync_with_stdio(false);

ii gems[300001];
int bags[300001] = {0, };

priority_queue<int> q;

int main() {
fastio

// input
int n, k; cin >> n >> k;

for (int i = 0; i < n; i++)
cin >> gems[i].first >> gems[i].second;

for (int i = 0; i < k; i++)
cin >> bags[i];

// Sort gems, bags ascending order
// gems sort by weight
sort(gems, gems + n);
sort(bags, bags + k);

// ans can be more then int max value
// 300,000 * 1,000,000
long long int ans = 0;
int cnt = 0;

for (int i = 0; i < k; i++) {
int curBag = bags[i];

// push all the gems that can put in current bag into the priority queue
while (cnt < n && gems[cnt].first <= curBag) {
q.push(gems[cnt].second);
cnt++;
}

// if queue is not empty, top of queue will be max price that can get in current bag
if (!q.empty()) {
ans += q.top();
q.pop();
}
}

printf("%lld\n", ans);
}
File renamed without changes.

0 comments on commit af6a387

Please sign in to comment.