-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3-H0ngJu #156
3-H0ngJu #156
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import sys | ||
import heapq | ||
|
||
line = int(sys.stdin.readline().strip()) | ||
|
||
heap = [] | ||
heapq.heapify(heap) | ||
|
||
for i in range(line): | ||
data = list(map(int, sys.stdin.readline().strip().split())) | ||
for s in data: | ||
if len(heap) < line: | ||
heapq.heappush(heap, s) | ||
else: | ||
if s > heap[0]: | ||
heapq.heappop(heap) | ||
heapq.heappush(heap, s) | ||
Comment on lines
+9
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ง๊ธ์ ๋ญ ํ๋ก์ ํธ๋ ์๋์ง๋ง ์ฝ๋ ๋ฆฌ๋ทฐ๋ฅผ ๋ฐ๋ ์์คํ ์ด๋ค ๋ณด๋๊น... PSํ ๋ ํด๋ฆฐ ์ฝ๋๋ ์ค๋ฒ ์์ง๋์ด๋ง์ด๊ธด ํ์ง๋ง, ์์ฆ์ ์ฝ๋๊ฐ ๊ธธ์ด์ง๋ ๊ตฌํ ๋ฌธ์ ๋ ๋ง์ด ๋์ค๊ธฐ ๋๋ฌธ์ ๋๋ฌด ๋ง์ ์๊ฐ์ ๋ค์ด์ง๋ ๋ง๊ณ ์ต์ํ์ ๋ ธ๋ ฅ(?) ์ ๋๋ ํด์ฃผ๋ฉด ์ข๋ค๊ณ ์๊ฐํฉ๋๋ค! ๊ทธ๋ฆฌ๊ณ ์ง๊ธ์ ์๊ฐ ์ ํ์ด ์๋ ์ํ๋ ์๋๊ธฐ์ ์ด๋ฐ ํด๋ฆฐ ์ฝ๋๋ฅผ ์ฒดํ ์ํค๊ธฐ์๋ ์ข์ ๊ฒ ๊ฐ๋ค๊ณ ์๊ฐ์ด ๋์ด์์! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ค์ค ์ข์ ๋ฆฌ๋ทฐ ๊ฐ์ฌํฉ๋๋ค (_ _) ์๋ง ์ ๋น์์๋ i๋ ๋จ์ ๋ฐ๋ณต๋ฌธ์ ์ํ ๋ณ์, s๋ ๋จ์ํ ์์๋ฅผ data์์ ๊บผ๋ด์จ๋ค๊ณ ์๊ฐํด์ ์ผ๋ ๊ฒ ๊ฐ๋ค์ฉ ํผ๋๋ฐฑ์ ๋ฐ์ํ๋ฉด, for _ in range(line):๊ณผ for num in data:๋ก ๊ฐ๊ฐ i์ s๋ฅผ ์์ ํ ์ ์๊ฒ ๋ค์!
Comment on lines
+15
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๊ฒฐ๊ตญ ํ ์์ฒด๊ฐ ํฌ๊ธฐ ๋น๊ต๋ฅผ ์ํ ์๋ฃ๊ตฌ์กฐ์ด๊ธฐ ๋๋ฌธ์, ์กฐ๊ฑด๋ฌธ์ ๋ฌ์๋์ ํ์ ์์ด ๋ฐ๋ก push ํ popํ๋ฉด ๋ฉ๋๋ค! heapq.heappush(heap, s)
heapq.heappop(heap)
|
||
|
||
print(heap[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ด ํจ์๋ ์ฌ๊ธฐ์์ ํธ์ถ์ํ์ ๋ ๋ผ์
heap ๋ฆฌ์คํธ ์์ ํธ๋ฆฌ๋ฅผ ์ฌ ๊ตฌ์ฑํ๋๊ฑฐ๋ผ ๋น์ด์์ ๋๋ ๋ถํ์ํ ํธ์ถ์ด๋๋๋ค