#include <bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=0x7fffffff;
const int N =5e5+10;
const int maxn = 200010;
ll n , k ;
pll pr[100010];
ll res =0 ;
ll cmp(pair<int , int > a , pair < int , int > b){
return a.second > b.second;
}
priority_queue<ll , vector<ll > , greater<ll > > qe;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >>n;
for(int i=0 ;i<n;i++){
cin >>pr[i].first >> pr[i].second;
}
sort(pr,pr+n ,cmp);
ll ma =0 ;ll sum =0 ;
for(int i=0;i<n;i++){
while(qe.size() >= pr[i].second){
ma -= qe.top();
qe.pop();
}
qe.push(pr[i].first);
ma +=pr[i].first;
sum = max(sum ,ma);
}
cout<<sum<<endl;
return 0;
}
原文:https://www.cnblogs.com/QFNU-ACM/p/13089818.html