Cod sursa(job #3131250)

Utilizator FlaviaF7Fota Stefania-Flavia FlaviaF7 Data 19 mai 2023 17:05:45
Problema Heapuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.25 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

set<int> multipliiE;
vector<int> elemente;
int auxiliar = 0;
ifstream in("heapuri.in");
ofstream out("heapuri.out");

void inserareElement(int nr) {
    elemente.push_back(nr);
    multipliiE.insert(nr);
}

void stergereElement(int pozitie) {
    int x = elemente[pozitie];
    multipliiE.erase(x);
}

int main() {
    int nrOperatii;
    in >> nrOperatii;
    vector<pair<int, int>> operatii;

    for (int i = 0; i < nrOperatii; ++i) {
        int tipOperatie, nr;
        in >> tipOperatie;
        if (tipOperatie == 1 || tipOperatie == 2) {
            in >> nr;
            operatii.push_back({tipOperatie, nr});
        } else {
            operatii.push_back({tipOperatie, -1});
        }
    }

    for (const auto& op : operatii) {
        int tipOperatie = op.first;
        int nr = op.second;

        if (tipOperatie == 1) {
            inserareElement(nr);
        } else if (tipOperatie == 2) {
            stergereElement(nr - 1);
        } else if (tipOperatie == 3) {
            out << *multipliiE.begin() << endl;
        }
    }

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

    return 0;
}