목록heap (1)
cmod.ify
[11286] 절댓값 힙
음수 양수 체크하려고 튜플 형식으로 처리함 import sysfrom heapq import *input = sys.stdin.readlineheap = []n = int(input())answer = []for i in range(n): x = int(input()) if x != 0: if x 0: b = 0 # 음수 x = -x else: b = 1 # 양수 heappush(heap, (x, b)) elif x == 0: if heap: px, pb = heappop(heap) if pb == 0: ans..
BASIC/코딩테스트
2026. 1. 6. 16:29