-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_1202.cpp
More file actions
46 lines (39 loc) · 901 Bytes
/
BOJ_1202.cpp
File metadata and controls
46 lines (39 loc) · 901 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
// 22 / 1 / 5
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int n, k;
vector<pair<int, int>> jewel;
vector<int> bag;
priority_queue<int> pq;
int main(void)
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
jewel.assign(n, pair<int, int>(0, 0));
bag.assign(k, 0);
for (int i = 0; i < n; i++)
cin >> jewel[i].first >> jewel[i].second;
for (int i = 0; i < k; i++)
cin >> bag[i];
sort(jewel.begin(), jewel.end());
sort(bag.begin(), bag.end());
long long answer = 0;
int j = 0;
for (int i = 0; i < k; i++)
{
int nowBag = bag[i];
while ((j < n) && (jewel[j].first <= nowBag))
pq.push(jewel[j++].second);
if (!pq.empty())
{
answer += pq.top();
pq.pop();
}
}
cout << answer;
return 0;
}