Skip to content

Commit

Permalink
Merge pull request #61 from AlgoLeadMe/15-seongwon030
Browse files Browse the repository at this point in the history
15-seongwon030
  • Loading branch information
seongwon030 authored Jun 30, 2024
2 parents 8f6a3fa + 5e80ca5 commit c0dd36d
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import heapq

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)

T = int(input())
for i in range(T):
max_heap = []
min_heap = []
re = []

n = int(input())
if n%2 == 0:
print(n//2)
else:
print(n//2+1)

for j in range(n//10 + 1):
arr = list(map(int,input().split()))
for k in range(len(arr)):
push_num(arr[k])
if k%2 == 0:
re.append(-max_heap[0])
if n%2 == 0:
re.append(-max_heap[0])

cnt = 0
for p in range(len(re)):
cnt += 1
print(re[p],end=' ')
if cnt%10 == 0:
print()
print()

0 comments on commit c0dd36d

Please sign in to comment.