dev/algorithm
BOJ / 14235๋ฒ / ํฌ๋ฆฌ์ค๋ง์ค ์ ๋ฌผ [Python3]
crscnt
2020. 12. 1. 21:00
๐ฉ๐ป๐ป ๋ฌธ์
14235๋ฒ: ํฌ๋ฆฌ์ค๋ง์ค ์ ๋ฌผ
ํฌ๋ฆฌ์ค๋ง์ค์๋ ์ฐํ๊ฐ ์ฐฉํ ์์ด๋ค์๊ฒ ์ ๋ฌผ์ ๋๋ ์ค๋ค. ์ฌํด๋ ์ฐํ๋ ์ ๋ฌผ์ ๋๋ ์ฃผ๊ธฐ ์ํด ๋ง์ ๋ ธ๋ ฅ์ ํ๊ณ ์๋๋ฐ, ์ ์ธ๊ณ๋ฅผ ๋์๋๊ธฐ๋ฉฐ ์ฐฉํ ์์ด๋ค์๊ฒ ์ ๋ฌผ์ ๋๋ ์ค ๊ฒ์ด๋ค. ํ์ง๋ง
www.acmicpc.net
โ๐ป ํ์ด
๐จ Python3
# https://www.acmicpc.net/problem/14235
import sys, heapq
if __name__ == "__main__":
n = int(sys.stdin.readline())
h = []
for i in range(n):
inputs = list(map(int, sys.stdin.readline().split()))
if inputs[0] == 0:
if len(h) == 0:
print(-1)
else:
print(-1*heapq.heappop(h))
else:
for j in range(1, inputs[0]+1):
heapq.heappush(h, -1*inputs[j])
728x90