-
Notifications
You must be signed in to change notification settings - Fork 0
/
2013_14_C1_4.cpp
61 lines (48 loc) · 933 Bytes
/
2013_14_C1_4.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
Day 8, Week 17 : March 8, 2014
Nice use of Greedy Algorithm to solve a problem
*/
#include <iostream>
#include <stdio.h>
#include <queue>
#include <algorithm>
#define Z 300005
typedef long long ll;
using namespace std;
struct jewel{
int m,v;
};
bool cmp(jewel a, jewel b){
return a.m < b.m;
}
jewel a[Z];
int bag[Z];
int main()
{
int N,K,i;
cin >> N >> K;
for(i = 0; i < N; i++){
cin >> a[i].m >> a[i].v;
}
for(i = 0; i < K; i++)
cin >> bag[i];
sort(bag, bag+K);
sort(a, a+ N, cmp);
ll ans;
int j;
priority_queue<int> pq;
ans = 0ll;
j = 0; int now;
while(!pq.empty()) pq.pop();
for(i = 0; i < K; i++){
for(; a[j].m <= bag[i]; j++){
pq.push(a[i].v);
}
if(!pq.empty()){
now = pq.top(); pq.pop();
ans += now;
}
}
cout<<ans<<endl;
return 0;
}