-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1202.cpp
41 lines (39 loc) · 862 Bytes
/
1202.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
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
vector<pair<int, int>>items;
vector<int>bag;
priority_queue<int, vector<int>>pq;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
int a, b;
for(int i = 0; i < n; i++){
cin >> a >> b;
items.push_back({a, b});
}
for(int i = 0; i < k; i++){
cin >> a;
bag.push_back(a);
}
sort(items.begin(), items.end());
sort(bag.begin(), bag.end());
long long int answer = 0;
int idx = 0;
for(int i = 0; i < k; i++){
while(idx < n && bag[i] >= items[idx].first){
pq.push(items[idx].second);
idx++;
}
if(!pq.empty()){
answer += pq.top();
pq.pop();
}
}
cout << answer;
}