Từ 2026 - Thuật toán nâng cao (thầy Hoàng - chiều thứ 7), 2026 - Lớp Thuật toán (Cô Chinh) - Thứ 7
Thông tin
include<bits/stdc++.h>
using namespace std; using ll=long long;
ll n,m,i,j,c[300005],res; pair<ll,ll>a[300005]; priority_queue<ll>q;
int main(){ ios::syncwithstdio(0); cin.tie(0);
cin>>n>>m;
for(i=1;i<=n;i++) cin>>a[i].first>>a[i].second;
for(i=1;i<=m;i++) cin>>c[i];
sort(a+1,a+n+1);
sort(c+1,c+m+1);
j=1;
for(i=1;i<=m;i++){
while(j<=n&&a[j].first<=c[i]){
q.push(a[j].second);
j++;
}
if(q.size()){
res+=q.top();
q.pop();
}
}
cout<<res;
}