题意:


思路:






#include <cstdio>
#include <queue>
#include <algorithm>
#include <iostream>
using namespace std;
const int N = 1e4 + 10;
struct Node{
    int p,d;
}a[N];
bool cmp(Node a,Node b){
    return a.d < b.d;
}
int n;
int main(){
    while(~scanf("%d",&n)){
        for(int i = 1;i <= n;i++){
            scanf("%d%d",&a[i].p,&a[i].d);
        }
        sort(a + 1,a + 1 + n,cmp);
        priority_queue< int,vector<int>,greater<int> > q;
        for(int i = 1;i <= n;i++){
            int t = a[i].d,w = a[i].p;
            //cout<<t<<" "<<w<<endl;
            q.push(w);
            if(q.size() > t) q.pop();
        }
        int ans = 0;
        while(q.size()){
            ans += q.top();
            q.pop();
        }
        printf("%d\n",ans);
    }
    return 0;
}