forked from encrypted-def/basic-algo-lecture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1202.cpp
41 lines (34 loc) · 841 Bytes
/
1202.cpp
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
// Authored by : BaaaaaaaaaaarkingDog
// Co-authored by : -
// http://boj.kr/ac7c8dedea8b446b9f85563064ed3a6f
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
int n, k;
pair<int, int> jewel[300003]; // {가격, 무게}
multiset<int> bag;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
// 정렬의 편의를 위해 무게/가격을 반대로 입력받음
for(int i = 0; i < n; i++)
cin >> jewel[i].Y >> jewel[i].X;
sort(jewel, jewel+n);
for(int i = 0; i < k; i++){
int c;
cin >> c;
bag.insert(c);
}
long long ans = 0;
for(int i = n-1; i >= 0; i--){
int m, v;
tie(v, m) = jewel[i];
auto it = bag.lower_bound(m);
if(it == bag.end()) continue;
ans += v;
bag.erase(it);
}
cout << ans;
}