1715 - 카드 정렬하기


1715 - 카드 정렬하기

1234567891011121314import heapqn = int(input())cards = []for _ in range(n): heapq.heappush(cards, int(input())) summation = 0while len(cards) > 1: x = heapq.heappop(cards) y = heapq.heappop(cards) summation += x + y heapq.heappush(cards, x + y) print(summation)cs 가장 적은 비교는 최소의 값 2개를 비교하는 것이다. 루프에서 매번 정렬 후 처리하는 것보다 효율적인 처리를 위해 최소힙을 구성하였다....

1715 - 카드 정렬하기에 대한 요약내용입니다.

자세한 내용은 아래에 원문링크를 확인해주시기 바랍니다.



원문링크 : 1715 - 카드 정렬하기