-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_1202.cpp
More file actions
45 lines (36 loc) · 831 Bytes
/
BOJ_1202.cpp
File metadata and controls
45 lines (36 loc) · 831 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
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
const int MAX = 300000;
int N, K;
int bag[MAX];
pair<int, int> jewelry[MAX];
priority_queue<int> pq;
int main(void)
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> N >> K;
for (int i = 0; i < N; i++)
cin >> jewelry[i].first >> jewelry[i].second;
for (int i = 0; i < K; i++)
cin >> bag[i];
sort(jewelry, jewelry + N);
sort(bag, bag + K);
long long result = 0;
int idx = 0;
for (int i = 0; i < K; i++)
{
while (idx < N && jewelry[idx].first <= bag[i])
pq.push(jewelry[idx++].second);
if (!pq.empty())
{
result += pq.top();
pq.pop();
}
}
cout << result << "\n";
return 0;
}