-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1202.cpp
More file actions
47 lines (38 loc) · 879 Bytes
/
Copy path1202.cpp
File metadata and controls
47 lines (38 loc) · 879 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
47
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#define MAX 300001
using namespace std;
int N; // 보석 수
int K; // 가방수
pair<int, int> v_jewerly[MAX];
int v_bag[MAX];
priority_queue<int, vector<int>, less<int>> pq;
long long solve() {
sort(v_jewerly, v_jewerly+N);
sort(v_bag, v_bag+K);
int idx = 0;
long long sum = 0;
for (int i = 0; i < K; i++) {
while (idx < N && v_bag[i] >= v_jewerly[idx].first) {
pq.push(v_jewerly[idx].second);
idx++;
}
if (!pq.empty()) {
sum += pq.top();
pq.pop();
}
}
return sum;
}
int main() {
cin >> N >> K;
for (int i = 0; i < N; ++i) {
cin >> v_jewerly[i].first >> v_jewerly[i].second;
}
for (int i = 0; i < K; ++i) {
cin >> v_bag[i];
}
cout << solve();
}