Cod sursa(job #1816724)

Utilizator andrey2397Barbu Andrei Octavian andrey2397 Data 26 noiembrie 2016 20:12:46
Problema Heapuri Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 1 kb
 #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;
}