-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d5e4b2
commit a0f7a9e
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import heapq | ||
import sys | ||
|
||
input = sys.stdin.readline | ||
|
||
max_heap = [] | ||
min_heap = [] | ||
def push_num(num): | ||
# max_heap과 min_heap 크기 같으면 max_heap에 넣음 | ||
if len(max_heap) == len(min_heap): | ||
heapq.heappush(max_heap, -num) | ||
else: | ||
# 크기가 다르면 이전에 max_heap에 넣은 것이므로 | ||
# min_heap에 넣는다 | ||
heapq.heappush(min_heap, num) | ||
|
||
if min_heap and -max_heap[0] > min_heap[0]: | ||
min = heapq.heappop(min_heap) | ||
max = -heapq.heappop(max_heap) | ||
heapq.heappush(max_heap, -min) | ||
heapq.heappush(min_heap, max) | ||
|
||
n = int(input()) | ||
for i in range(n): | ||
push_num(int(input())) | ||
print(-max_heap[0]) |