Pagini recente » Cod sursa (job #3223772) | Cod sursa (job #1845702) | Cod sursa (job #173106) | Cod sursa (job #2395487) | Cod sursa (job #2744938)
#include <iostream>
#include <fstream>
#include <set>
#include <vector>
using namespace std;
ifstream f("heapuri.in");
ofstream g("heapuri.out");
vector<int> pozitii;
set<int> h;
void push(int x){
h.insert(x);
pozitii.push_back(x);
}
auto index(int x){
set<int>::iterator it;
int cnt = 0;
for(it = h.begin(); it!=h.end(); it++){
if(*it == x) return it;
}
return h.end();
}
void pop(int x){
int poz = pozitii[x-1];
auto gasit = index(poz);
if(gasit != h.end()) h.erase(gasit);
}
int peak(){
return *h.begin();
}
int main(){
int n, operatie, x;
f>>n;
for(int i=0;i<n;i++){
f>>operatie;
if(operatie == 1){
f>>x;
push(x);
} else{
if(operatie == 2){
f>>x;
pop(x);
}else g<<peak()<<'\n';
}
}
return 0;
}