题目链接
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
const int N = 100010;
#define int long long
int n;
typedef pair<int,int>PII;
priority_queue<int,vector<int>,greater<int>>heap;
PII a[N];
signed main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
int v,s;
cin>>v>>s;
a[i]={s,v};
}
sort(a+1,a+n+1,greater<PII>());
int res=0,tmp=0;
for(int i=1;i<=n;i++)
{
heap.push(a[i].second);
tmp+=a[i].second;
while(heap.size()>a[i].first)
{
tmp-=heap.top();
heap.pop();
}
res=max(res,tmp);
}
cout<<res<<endl;
}