Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8-yuyu0830 #33

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}