Cod sursa(job #1086718)

Utilizator Dddarius95Darius-Florentin Neatu Dddarius95 Data 18 ianuarie 2014 14:39:25
Problema Heapuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.84 kb
#include <algorithm>
#include <fstream>
#include <vector>
#define Nmax 200999
using namespace std;
ifstream f("heapuri.in");
ofstream g("heapuri.out");
int N,K,poz[Nmax];
vector <int> v;

bool cmp(const int &A,const int &B)
{
    return A>B;
}

int main()
{
    f>>N;
    make_heap (v.begin(),v.end(),cmp);
    for(int i=1;i<=N;++i)
    {
        int tip;
        f>>tip;
        if(tip==1)
        {
            int x;
            f>>x;
            v.push_back(x);
            push_heap(v.begin(),v.end());
            poz[++K]=x;
        }
        else
        if(tip==2)
        {
            int x;
            f>>x;
            pop_heap (v.begin(),v.end());
            v.pop_back();
        }
        else
        {
            g<<v.front()<<'\n';
        }
    }

    f.close();g.close();
    return 0;
}