挂了,总是UKE
查看原帖
挂了,总是UKE
648996
_orange_楼主2023/1/29 10:27
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
priority_queue<int,vector<int>,greater<int> >q;
priority_queue<int,vector<int> >r;
int main(){
    ios::sync_with_stdio(false);
	int opt; 
	cin>>opt;
	q.push(opt);//q 1
	while(cin>>opt){
		if(opt==-1){
			cout<<q.top()<<endl;
			q.pop();
			goto where;
		}
		if(opt==0){
			break;
		}
		if(opt<q.top())r.push(opt);
		if(opt>=q.top())q.push(opt);//q 1 3 q 5 7 q 7 9 11
		where:;
		if(q.size()>r.size()+1){
			r.push(q.top());
			q.pop();
		}//r 1 3 5 6 q 7 9 11
		if(q.size()<r.size()){
			q.push(r.top());
			r.pop();
		}
	}
	return 0;
}
2023/1/29 10:27
加载中...