对各种STL容器还是不太熟悉以及自己的贪心策略总是太想当然了。QAQ
优先队列默认从大到小,加上greater以后从小到大。
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define INF 0x3f3f3f3f
#define PII pair<int, int>
#define rep(i, l, r) for (int i = l; i < r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define rep2(i, l, r) for (int i = l; i * i <= r; i++)
#define rep3(i, l, r) for (LL i = l; i * i * i <= r; i++)
#define Min(a, b) a > b ? b : a
#define Max(a, b) a > b ? a : b
#define endl '\n'
#define debug "-----"
using namespace std;
typedef long long LL;
const LL mod = 1e9;
const int N = 1e5 + 10, M = 10100;
LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
priority_queue<LL, vector<LL>, greater<LL>> pq;
struct Node
{
int v,s;
}sol[N];
bool cmp( Node a , Node b ){
return a.s > b.s;
}
int main()
{
IOS;
int n;
cin >> n;
rep( i , 1 , n+1 )
cin >> sol[i].v >> sol[i].s;
sort( sol+1 , sol+1+n , cmp );
LL ans = 0 , res = 0;
rep( i , 1 , n+1 ){
res += sol[i].v;
pq.push( sol[i].v );
while( pq.size() > sol[i].s ){
res -= pq.top();
pq.pop();
}
ans = max( res , ans );
}
cout << ans;
return 0;
}