-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBOJ_1202.cpp
More file actions
46 lines (40 loc) · 944 Bytes
/
BOJ_1202.cpp
File metadata and controls
46 lines (40 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define MOD 1000000000
const ll INF = 10e12 + 10;
using namespace std;
int Bag[303030];
priority_queue<int> pq;
vector<pii > jew;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) {
int m, v;
cin >> m >> v;
jew.push_back({m, v});
}
sort(jew.begin(), jew.end());
for (int i = 0; i < k; i++) {
cin >> Bag[i];
}
sort(Bag, Bag + k);
int idx = 0;
ll ans = 0;
for (int i = 0; i < k; i++) {
while (jew[idx].first <= Bag[i] && idx < n) {
// cout << jew[idx].second << " ";
pq.push(jew[idx].second);
idx++;
}
if (!pq.empty()) {
ans += pq.top();
pq.pop();
}
}
cout << ans;
}