题目链接tokitsukaze and Soldier
思路
降序排列,一个一个插入最小堆中,
每次弹出最小的以满足条件,记录
所有情况的即是答案

#include <bits/stdc++.h>
#define MAX_V 200005
#define MP make_pair
#define FOR(n, i) for (int i = 1; i <= n; i++)
#define For(n, i) for (int i = 0; i < n; i++)
using namespace std;
namespace fast {
inline char nc() {
    static char buf[100000], *L = buf, *R = buf;
    return L == R && (R = (L = buf) + fread(buf, 1, 100000, stdin), L == R)
               ? EOF
               : *L++;
}
template <class orz>
inline void qread(orz& x) {
    x = 0;
    char ch = nc();
    bool f = 0;
    while (ch < '0' || ch > '9') (ch == '-') && (f = 1), ch = nc();
    while (ch >= '0' && ch <= '9')
        x = (x << 3) + (x << 1) + (ch ^ 48), ch = nc();
    f && (x = -x);
}
}  // namespace fast
using namespace fast;
template <class orz>

inline void read(orz& x) {
    x = 0;
    bool f = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') (ch == '-') && (f = 1), ch = getchar();
    while (ch >= '0' && ch <= '9')
        x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    f && (x = -x);
}
template <class orz>
inline void out(orz x) {
    (x < 0) && (putchar('-'), x = -x);
    if (x > 9) out(x / 10);
    putchar(x % 10 + '0');
}
typedef long long ll;
typedef pair<int, int> PII;
const double PI = acos(-1);
const double esp = 1e-6;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
vector<PII> s;
priority_queue<ll, vector<ll>, greater<ll>> que;
bool cmp(PII x,PII y){
    return x.first>y.first;
}
int n;
int main() {
    read(n);
    For(n,i){
        int v,si;read(v);read(si);
        s.push_back(MP(si,v));
    }
    sort(s.begin(),s.end(),cmp);
    ll sum=0,ans=0;
    for(int i=0;i<s.size();i++){
        while((!que.empty())&&que.size()>=s[i].first){
            sum-=que.top();que.pop();
        }
        sum+=s[i].second;
        que.push(s[i].second);
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}
/*
 */