Cod sursa(job #3124206)
Utilizator | Data | 27 aprilie 2023 11:28:38 | |
---|---|---|---|
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()