为什么WA
查看原帖
为什么WA
220824
yyz1005楼主2022/5/27 13:50
#include<bits/stdc++.h>
using namespace std;
struct Node{
	int date;
	int pri;
	bool operator <(const Node &b) const{
		return (date==b.date?pri>b.pri:date<b.date);
	}
	bool operator >(const Node &b) const{
		return (date==b.date?pri<b.pri:date>b.date);
	}
};
priority_queue<Node,vector<Node>,greater<Node> > q;
int n;
Node a[10010];
int main(){
	while(cin >> n){
		for(int i = 1; i <= n; i++){
			scanf("%d%d",&a[i].pri,&a[i].date);
		}
		sort(a+1,a+n+1);
		for(int i = 1,j = 1; i <= n; i++){
			while(a[j+1].date==a[i].date) j++;
			int t = q.size()+1,ins = i;
			while(t<=a[i].date&&ins<=j){
				q.push(a[ins]);
				t++,ins++;
			}
			while(!q.empty()&&q.top().pri<a[ins].pri&&ins<=j){
				q.pop();
				q.push(a[ins]);
				ins++;
			}
			i = j;
		}
		int ans = 0;
		while(!q.empty()){
			ans+=q.top().pri;
			q.pop();
		}
		printf("%d\n",ans);
	}
	return 0;
}
2022/5/27 13:50
加载中...