#include <iostream>
#include <queue>
using namespace std;
struct node{
int a, fffff;
};
struct cmp{
bool operator()(const node &aa, const node &b){
return aa.a>b.a;
}
};
priority_queue<node, vector<node>, cmp> d;
int main(){
d.push((node){2, 0});
d.push((node){1, 0});
cout<<d.top().a;
}
另一种是algorithm的:
#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;
int d[1000005], n, k, tt, uu;
bool cmp(int a, int b){
return a>b;
}
int main(){
cin>>n;
//make_heap(d, d+1, cmp);
for(int i=1; i<=n; i++){
scanf("%d", &tt);
if(tt==1){
scanf("%d", &uu);
d[++k] = uu;
push_heap(d+1, d+1+k, cmp);
}
if(tt==2)
printf("%d\n", d[1]);
if(tt==3){
pop_heap(d+1, d+1+k, cmp);
k--;
}
}
return 0;
}