Cod sursa(job #3132232)

Utilizator AlexCRCAlexandru-Emilian Craciun AlexCRC Data 22 mai 2023 00:21:52
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.75 kb
#include <fstream>
#include <set>
#include <vector>

std::ifstream in("heapuri.in");
std::ofstream out("heapuri.out");

int n, op, elem;
std::set<int> heap;    
std::vector<int> order; 

int main()
{
    in >> n;
    while (n)
    {
        in >> op;
        if (op == 1)
        {
            in >> elem;
            heap.insert(elem);
            order.push_back(elem); 
        }
        else if (op == 2)
        {
            in >> elem;
            if (elem - 1 < order.size())
            {
                heap.erase(order[elem - 1]);
            }
        }
        else if (op == 3)
        {
            out << *heap.begin() << '\n';
        }
        n--;
    }

    in.close();
    out.close();

    return 0;
}