题目链接
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+20;
using ll =long long;
long long ans;
struct node{int x,y;bool operator < (node p) const{return x<p.x; //按截至时间从小到大排序 }
}a[N];
long long ti;
int main()
{map<int,int>mp;int n; cin>>n;for(int i=1;i<=n;i++){cin>>a[i].x>>a[i].y;}sort(a+1,a+1+n);priority_queue<ll,vector<ll>,greater<ll>>p;for(int i=1;i<=n;i++){if(ti<a[i].x){ti++;ans+=a[i].y;p.push(a[i].y);}else if(a[i].y>p.top()){ans-=p.top();ans+=a[i].y;p.pop();p.push(a[i].y); }}cout<<ans;}