Cod sursa(job #2618363)

Utilizator STEFAN-ZOTAZota Stefan-Daniel STEFAN-ZOTA Data 24 mai 2020 18:42:32
Problema Heapuri Scor 10
Compilator py Status done
Runda Arhiva educationala Marime 0.64 kb
f = open("heapuri.in")
g = open("heapuri.out", "w")
n = int(f.readline())
a = []
l = []
trebuieSterse = []
from heapq import heapify, heappush, heappop
for _ in range(n):
    aux = f.readline().split()
    comanda = aux[0]
    if comanda == '1':
        nr = aux[1]
        heappush(a, nr)
        l.append(nr)
    if comanda == '3':
        g.write(heappop(a) + "\n")
    if comanda == '2':
        nr = aux[1]
        if a[0] == nr:
            heappop(a)
        else:
            if a[0] in trebuieSterse:
                trebuieSterse.remove(a[0])
                heappop(a)
                trebuieSterse.append(nr)