16551 [백준] 1655 가운데를 말해요 (Python) - heapq import sys from heapq import heappush, heappop n = int(sys.stdin.readline()) # input() 사용시 시간 초과 발생 smaller = [] larger = [] for i in range(n): now = int(sys.stdin.readline()) if len(smaller) == len(larger): #가장 중요한 조건: left heap 과 right heap의 길이가 같거나 1차이여야 함 heappush(smaller, -now) #smaller : max heap else: heappush(larger, now) # larger : min heap if smaller and larger and -smaller[0] > larger.. 2023. 1. 21. 이전 1 다음