求助
查看原帖
求助
1055592
Orz___zrO楼主2023/10/27 20:21
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
//#define ll long long
typedef long long ll;
ll n;
priority_queue <ll,vector<ll>,greater<ll> > q;
struct Node{
    ll d,p;
} a[N];
bool cmp(Node a,Node b){
    return a.d<b.d;
}
int main(){
    cin>>n;
    for(ll i=1;i<=n;i++){
        cin>>a[i].d>>a[i].p;
    }
    sort(a+1,a+n+1,cmp);
    ll ans=0;
    for(ll i=1;i<=n;i++){
        if(a[i].d<=(int)q.size()){
            if(q.top()<a[i].p){
                ans+=a[i].p-q.top();
                q.pop();
                q.push(a[i].p);
            }
            else{
                ans+=a[i].p;
                q.push(a[i].p);
            }
        }
    }
    cout<<ans;
    return 0;
}

不知道错那,玄关

2023/10/27 20:21
加载中...