-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1202.cpp
More file actions
58 lines (47 loc) · 994 Bytes
/
1202.cpp
File metadata and controls
58 lines (47 loc) · 994 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
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> JEWEL;
vector<JEWEL> jewels;
vector<int> bags;
priority_queue<int> pq;
void solution(long long &answer)
{
int index = 0;
for (int i = 0; i < bags.size(); i++)
{
while (index < jewels.size() && jewels[index].first <= bags[i])
{
pq.push(jewels[index++].second);
}
if (!pq.empty())
{
answer += pq.top();
pq.pop();
}
}
}
int main()
{
int N, K;
int M, V, C;
long long answer = 0;
scanf("%d %d", &N, &K);
for (int i = 0; i < N; i++)
{
scanf("%d %d", &M, &V);
jewels.push_back({M, V});
}
for (int i = 0; i < K; i++)
{
scanf("%d", &C);
bags.push_back(C);
}
sort(jewels.begin(), jewels.end());
sort(bags.begin(), bags.end());
solution(answer);
printf("%lld\n", answer);
return 0;
}