112791 [백준/11279/파이썬(Pyhon)] 최대 힙 / heapq함수로 최대 힙 구현 [백준/11279/파이썬(Pyhon)] 최대 힙 / heapq함수 11279번: 최대 힙 (acmicpc.net) 코드 from sys import stdin import heapq heap = [] x = 0 N = int(stdin.readline()) for i in range(N): x = int(stdin.readline()) if x > 0: heapq.heappush(heap, -x) elif x == 0: if len(heap) == 0: print(0) else: print(-(heapq.heappop(heap))) 파이썬에는 heapq라는 라이브러리가 있다. 힙 라이브러리이다. import 해준다. heap 리스트와 수를 넣거나 0을 입력할 x를 초기화해준다. N번 반복을 위해 N을 입.. 2023. 2. 26. 이전 1 다음