Pagini recente » Cod sursa (job #2820547) | Cod sursa (job #2082738) | Cod sursa (job #3155445) | Cod sursa (job #1931179) | Cod sursa (job #1816724)
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;
const int NMAX=200001;
vector<int>v;
int poz=0, i, n, op, x, poz_stergere, ap[NMAX];
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
bool comp(int a, int b)
{
return a>b;
}
void adauga(int x)
{
v.push_back(x);
push_heap(v.begin(), v.end());
ap[++poz]=x;
}
void afiseaza_minim()
{
make_heap(v.begin(), v.end(), comp);
fout<<v.front()<<"\n";
}
void sterge(int pozitie)
{
/*
int elem_sters=ap[pozitie];
cout<<elem_sters<<"-elem sters \n";
*/
pop_heap(v.begin(), v.end());
v.pop_back();
}
int main()
{
fin>>n;
for(i=1;i<=n;i++){
fin>>op;
if(op==1){
fin>>x;
adauga(x);
}
else if(op==3){
afiseaza_minim();
}else if(op==2){
fin>>poz_stergere;
sterge(poz_stergere);
}
}
return 0;
}