这道题我不知道我这样做哪里错了,有人能帮我调一调或者举出一个反例吗?感激不尽。
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
using namespace std;
long long n,ans;
priority_queue<pair<long long,long long> > q;
struct node
{
int d,p;
}a[100010];
int main()
{
cin>>n;
for(int i=1; i<=n; i++)
{
scanf("%d%d",&a[i].d,&a[i].p);
q.push(make_pair(a[i].p,a[i].d));
}
int key=0,wei=0;
while(!q.empty())
{
long long x=q.top().second;
if(x>wei)
key=key+x-wei,wei=x;
if(key>0)
{
long long js=q.top().first;
ans+=js;
key--;
}
q.pop();
}
cout<<ans;
return 0;
}