标签:i++ 链接 http code solution 知识 amp 队列 while
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 5;
struct node{
ll v;
int s;
};
node a[maxn];
bool cmp(node p1,node p2){
return p1.s > p2.s;
}
priority_queue< ll ,vector<ll>,greater<ll> > q;//小根堆
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%lld %d",&a[i].v,&a[i].s);
}
sort(a+1,a+1+n,cmp);
ll ans = 0 , cnt = 0;
for(int i=1;i<=n;i++){
while(q.size() >= a[i].s){
cnt -= q.top();
q.pop();
}
q.push(a[i].v);
cnt += a[i].v;
ans = max(ans , cnt);
}
printf("%lld\n",ans);
return 0;
}
标签:i++ 链接 http code solution 知识 amp 队列 while
原文地址:https://www.cnblogs.com/QFNU-ACM/p/12565479.html