Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- 재귀
- BOJ
- 힙
- level1
- dict
- 운영체제
- 파이썬
- BFS
- DP
- level2
- 다익스트라
- 다이나믹 프로그래밍
- 구현
- 딕셔너리
- 수학
- 프로그래머스
- 브루트포스
- 스택
- level3
- MYSQL
- 그리디
- 가상메모리 관리
- N과M
- 가상메모리
- 코딩테스트
- 백준
- python
- level0
- programmers
- dfs
Archives
- Today
- Total
동캄의 코딩도장
백준 14241 [슬라임 합치기] 파이썬 본문
https://www.acmicpc.net/problem/14241
#백준 14241
import sys
import heapq
n=int(sys.stdin.readline())
lst=list(map(int,sys.stdin.readline().split()))
heapq.heapify(lst)
ans=0
for i in range(n-1):
x=heapq.heappop(lst)
y=heapq.heappop(lst)
ans+=x*y
heapq.heappush(lst,x+y)
print(ans)
그리디하게 해결하면 된다.
'코테 > BOJ' 카테고리의 다른 글
백준 20365 [블로그 2] 파이썬 (0) | 2022.09.04 |
---|---|
백준 16112 [5차 전직] 파이썬 (0) | 2022.09.04 |
백준 15903 [카드 합체 놀이] 파이썬 (0) | 2022.09.04 |
백준 1541 [잃어버린 괄호] 파이썬 (0) | 2022.09.04 |
백준 1931 [회의실 배정] 파이썬 (0) | 2022.09.04 |