πŸ—οΈ Algorithm/🟩 λ°±μ€€

🟩 [λ°±μ€€] [Python] [Class3] 1927번_μ΅œλŒ€ νž™

Dbswnstjd 2022. 11. 7. 00:48

문제

https://www.acmicpc.net/problem/11279

 

11279번: μ΅œλŒ€ νž™

첫째 쀄에 μ—°μ‚°μ˜ 개수 N(1 ≤ N ≤ 100,000)이 주어진닀. λ‹€μŒ N개의 μ€„μ—λŠ” 연산에 λŒ€ν•œ 정보λ₯Ό λ‚˜νƒ€λ‚΄λŠ” μ •μˆ˜ xκ°€ 주어진닀. λ§Œμ•½ xκ°€ μžμ—°μˆ˜λΌλ©΄ 배열에 xλΌλŠ” 값을 λ„£λŠ”(μΆ”κ°€ν•˜λŠ”) 연산이고, xκ°€

www.acmicpc.net

풀이

# λ°±μ€€ 11279번 문제 - μ΅œλŒ€ νž™
import sys
import heapq

n= int(input())
heap = []
for _ in range(n) :
    x = int(sys.stdin.readline())
    if x :
        heapq.heappush(heap, (-x, x))
    else :
        if len(heap) >= 1 :
            print(heapq.heappop(heap)[1])
        else :
            print(0)