You are viewing a single comment's thread. Return to all comments →
import heapq q = int(input()) heap = [] dic = {} for _ in range(q): query = input() if query[0] == '1': query = query.split() heapq.heappush(heap,int(query[1])) elif query[0] == '2': query = query.split() dic[int(query[1])] = 1 while len(heap) > 0 and heap[0] in dic: heapq.heappop(heap)
else: print(heap[0])
Seems like cookies are disabled on this browser, please enable them to open this website
QHEAP1
You are viewing a single comment's thread. Return to all comments →
import heapq q = int(input()) heap = [] dic = {} for _ in range(q): query = input() if query[0] == '1': query = query.split() heapq.heappush(heap,int(query[1])) elif query[0] == '2': query = query.split() dic[int(query[1])] = 1 while len(heap) > 0 and heap[0] in dic: heapq.heappop(heap)