Cod sursa(job #3128774)

Utilizator JohnnyFortaPascu Ioan JohnnyForta Data 10 mai 2023 21:19:20
Problema Heapuri Scor 0
Compilator py Status done
Runda Arhiva educationala Marime 0.51 kb
import heapq

f = open('heapuri.in')
g = open('heapuri.out', 'w')

heap = []
order = []

heapq.heapify(heap)

n = int(f.readline())

for _ in range(n):
    cm = f.readline().split()
    if cm[0] == '1':
        x = int(cm[1])
        heapq.heappush(heap, x)
        order.append(x)
    if cm[0] == '2':
        ind = int(cm[1])
        ind -= 1
        x = order[ind]
        heap.remove(x)
        heapq.heapify(heap)
    if cm[0] == '3':
        g.write(str(heap[0]) + '\n')

f.close()
g.close()