Cod sursa(job #1899997)

Utilizator hantoniusStan Antoniu hantonius Data 3 martie 2017 08:47:32
Problema Heapuri Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.78 kb
#include <iostream> // sterge
#include <fstream>
#include <set>
#define maxn 200001
using namespace std;

ifstream fin("heapuri.in");
ofstream fout("heapuri.out");

multiset <int> my_set;
multiset <int>::iterator it;
int n, v[maxn], vf;

int main()
{
    int a, b;

    fin >> n;
    for (int i = 1; i <= n; i++) {
        cout << i << '\n';
        fin >> a;
        if (a == 1 || a == 2)
            fin >> b;
        if (a == 1) {
            v[++vf] = b;
            my_set.insert(b);
        }
        else if (a == 2) {
            it = my_set.find(v[b]);
            my_set.erase(*it);
        }
        else {
            it = my_set.begin();
            fout << *it << '\n';
            my_set.erase(my_set.begin());
        }
    }
    return 0;
}