分类:贪心
题目链接:LA2757-Supermarket
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn=10000+5;
struct node
{
int p,d;
}a[maxn];
bool cp(const node &x,const node &y)
{
return x.d<y.d;
}
int main()
{
int n,ans;
while(scanf("%d",&n))
{
ans=0;
for(int i=0;i<n;i++)
{
scanf("%d %d",&a[i].p,&a[i].d);
}
sort(a,a+n,cp);
priority_queue<int,vector<int>,greater<int> > q;
for(int i=0;i<n;i++)
{
if(a[i].d>q.size())
{
ans+=a[i].p;
q.push(a[i].p);
}
else if(a[i].p>q.top())
{
ans-=q.top();
q.pop();
q.push(a[i].p);
ans+=a[i].p;
}
}
printf("%d\n",ans);
}
return 0;
}