Cod sursa(job #1922338)

Utilizator doroftei1999Doroftei Andrei doroftei1999 Data 10 martie 2017 17:03:12
Problema Heapuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.84 kb
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream in("heapuri.in");
ofstream out("heapuri.out");

int main() {
    int k;
    vector<int> v, z;
    in >> k;
    for(int i = 0; i < k; i++) {
        make_heap(v.begin(), v.end());
        sort_heap(v.begin(), v.end());
        int x;
        in >> x;
        if(x == 1) {
            int y;
            in >> y;
            v.push_back(y);
            push_heap(v.begin(), v.end());
            z.push_back(y);
        }
        else if(x == 2) {
            int a;
            in >> a;
            a--;
            v.erase(find(v.begin(), v.end(), z[a]));
            z.erase(find(z.begin(), z.end(), z[a]));
            sort_heap(v.begin(), v.end());
        }
        else
            out << v.front() << '\n';
    }
    return 0;
}