编译后说cmp函数有问题,求大佬指点
  • 板块学术版
  • 楼主Lycdeer
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/8/9 22:16
  • 上次更新2024/8/9 22:30:36
查看原帖
编译后说cmp函数有问题,求大佬指点
1088782
Lycdeer楼主2024/8/9 22:16
#include<bits/stdc++.h>
using namespace std;
struct node{
	long long t1,t2;
}a[150005];
long long ans,t;
bool cmp(node c,node b){
	return c.t2<b.t2;
}
priority_queue<node>q; 
int main(){
	int n; cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i].t1>>a[i].t2;
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++){
		if(a[i].t1<a[i].t2-t){
			q.push(a[i]);
			t+=a[i].t1;
			ans++;
		}
		else{
			if(a[i].t1<q.top().t1){
				t-=q.top().t1;
				q.push(a[i]);
				t+=q.top().t1;
			}
		}
	} 
	cout<<ans;
	return 0;
}
2024/8/9 22:16
加载中...