문제
https://www.acmicpc.net/problem/1715
코드
import heapq
n=int(input())
array=[int(input()) for _ in range(n)]
heapq.heapify(array)
result=0
while len(array)>1:
t1=heapq.heappop(array)
t2=heapq.heappop(array)
temp=t1+t2
result+=temp
heapq.heappush(array,temp)
print(result)
생각 정리
n이 10만인것을 확인 못하고 dp를 통해 해결하려다 메모리 초과가 떴다....
'문제풀이 > 그리디' 카테고리의 다른 글
[JAVA] [그리디] Pro 마법의 엘리베이터 (0) | 2023.07.10 |
---|---|
[JAVA] [그리디] 백준 1339 단어수학 (0) | 2023.06.19 |
[파이썬] [그리디] 백준 17615 볼 모으기 (0) | 2023.03.02 |
[파이썬] [그리디] 백준 2138 전구와 스위치 (0) | 2023.02.10 |
[파이썬] [그리디] Pro 단속카메라 (0) | 2022.02.19 |