-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1202.cpp
More file actions
31 lines (31 loc) · 708 Bytes
/
1202.cpp
File metadata and controls
31 lines (31 loc) · 708 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
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n, k, MAX;
ll ans;
multiset<ll> bag;
priority_queue<pair<int,int>> pq;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
for(int i = 0; i < n; i++) {
ll a, b; cin >> a >> b;
pq.push({b, a});
}
for(int i = 0; i < k; i++) {
ll x; cin >> x;
bag.insert(x);
}
while(!pq.empty() && bag.size()) {
auto cur = pq.top(); pq.pop();
ll value = cur.first;
ll heavy = cur.second;
auto it = bag.lower_bound(heavy);
if(it != bag.end()) {
ans += value;
bag.erase(it);
}
}
cout << ans;
}