파이썬 1715 (1) 썸네일형 리스트형 백준 1715번: 카드 정렬하기 파이썬 코드(우선순위 큐) #1715 import heapq import sys n = int(sys.stdin.readline()) heap = [] carculate = [] for _ in range(n): card = int(sys.stdin.readline()) heapq.heappush(heap, card) while len(heap) > 1: temp1 = heapq.heappop(heap) temp2 = heapq.heappop(heap) carculate.append(temp1 + temp2) heapq.heappush(heap,temp1 + temp2) print(sum(carculate)) 설명 숫자끼리 더하면서 생기는 연산을 모았다가 더하면 되는 문제이다. 다만 적은 수끼리 더하는 것이 연산이 적기 때문에, .. 이전 1 다음