[Greedy] 1715번 - 단어 정렬(56일차)

bob.sort·2021년 9월 1일
0
post-thumbnail
post-custom-banner
import sys
import heapq
input = sys.stdin.readline

N = int(input())
card_list = []
card_heap = []

for _ in range(N):
  heapq.heappush(card_heap, int(input()))

if(len(card_list) == 1):
  print(0)
else:

  while(len(card_heap) != 1):
    card1 = heapq.heappop(card_heap)
    card2 = heapq.heappop(card_heap)
    
    heapq.heappush(card_heap, card1+card2)
    card_list.append(card1+card2)

  print(sum(card_list))
profile
Interest in Computer Graphics and Computer Vision

0개의 댓글