33分求助qwq
查看原帖
33分求助qwq
258081
zhangjinyan楼主2021/11/20 20:32

尽管和题解代码长得非常像,但不知道为啥就是不对

#include<bits/stdc++.h>
using namespace std;
struct node
{
	long long d,p;
}a[100005];
bool operator <(node x,node y)
{
	return x.p>y.p; 
}
bool cmp(const node x,const node y)
{
	return x.d<y.d;
}
int n;
long long ans;
priority_queue<node> s;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].d>>a[i].p;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		//cout<<a[i].d<<" "<<s.size()<<endl;
		//system("pause");
		if(a[i].d>s.size())
		{
			s.push(a[i]);
			ans+=a[i].p;
		}else
		{
			if(a[i].p>s.top().p)
			{
				s.pop();
				ans+=a[i].p-s.top().p;
				s.push(a[i]);
			} 
		}
	}
	cout<<ans<<endl;
} 

求助大佬

2021/11/20 20:32
加载中...