Cod sursa(job #2622469)

Utilizator ihorvaldsTudor Croitoru ihorvalds Data 1 iunie 2020 12:55:51
Problema Heapuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#include <fstream>
#include <vector>

void push(std::vector<int>& v, int val) {
    int i = 0;
    for (; i < v.size() && v[i] < val; i++);
    v.insert(v.begin() + i, val);
}

void remove(std::vector<int>& v, int val) {
    std::vector<int>::iterator found = std::find(v.begin(), v.end(), val);

    if (found != v.end())
        v.erase(found);
}

int main() {
    std::ifstream f("heapuri.in");
    std::ofstream g("heapuri.out");

    std::vector<int> v, ord;
    int command, n, tmp;
    f >> n;
    for (int i = 0; i < n; i++) {
        f >> command;

        if (command == 1) {
            f >> tmp;
            push(v, tmp);
            ord.push_back(tmp);
        }

        if (command == 2) {
            f >> tmp;
            remove(v, ord[tmp - 1]);
        }

        if (command == 3) {
            g << v[0] << "\n";
        }
    }
}