Skip to content
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

[김지원] 카드 정렬하기 #252

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions solution/BOJ_1715_카드_정렬하기/김지원.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import heapq

N = int(input())
card_deck = []
for _ in range(N):
heapq.heappush(card_deck, int(input()))


if len(card_deck) == 1: #1개일 경우 비교하지 않아도 된다
print(0)
else:
answer = 0
while len(card_deck) > 1: #1개일 경우 비교하지 않아도 된다
temp_1 = heapq.heappop(card_deck) #제일 작은 덱
temp_2 = heapq.heappop(card_deck) #두번째로 작은 덱
answer += temp_1 + temp_2 #현재 비교 횟수를 더해줌
heapq.heappush(card_deck, temp_1 + temp_2) #더한 덱을 다시 넣어줌

print(answer)