ALDS1_9_C: Priority Queue (続き4)
heapqを使って
from sys import stdin
from heapq import heappush, heappop
def main():
Q = []
for line in stdin.readlines():
cmd = line.split()
if cmd[0] == "insert":
heappush(Q, -int(cmd[1]))
elif cmd[0] == "extract":
print(-heappop(Q))
else:
break
if __name__ == "__main__":
main()
瞬殺
heapqはpopすると最小の値を返すようになっているのでマイナスにしています