
[Baekjoon] 1655. 가운데를 말해요
·
코딩테스트/Python
🔗 Problem Linkhttps://www.acmicpc.net/problem/1655❔ThinkingN개의 수가 차례대로 주어질 때, 현재까지 숫자들의 중앙값을 출력한다.각 숫자는 -10,000이상 10,000이하의 정수이다.💻Solutionimport sysimport heapqinput = sys.stdin.readlinemax_heap = []min_heap = []N = int(input().rstrip())for _ in range(N): num = int(input().rstrip()) heapq.heappush(max_heap, -num) if max_heap and min_heap and (-max_heap[0] > min_heap[0]): heapq...