Notice
Recent Posts
Recent Comments
Link
나의 개발일지
[백준] 15903 카드 합체 놀이 [Python, 파이썬] 본문
- 문제 : https://www.acmicpc.net/problem/15903
- 🔑 그리디, 우선 순위 큐
- 카드들을 heap에 담고 가장 작은 카드를 두 개 뽑아낸다.
- 뽑아낸 카드 두 개를 합쳐서 두 번 집어넣는다.
- 이 과정을 m번 반복하고 힙에 남은 카드들의 전체 합계를 구한다.
- 끝 ✨
from heapq import heapify, heappop, heappush
n, m = map(int, input().split())
card = list(map(int, input().split()))
heapify(card)
for _ in range(m):
x = heappop(card)
y = heappop(card)
heappush(card, x+y)
heappush(card, x+y)
print(sum(card))
'백준' 카테고리의 다른 글
[백준] 17299 오등큰수 [Python, 파이썬] (0) | 2023.12.01 |
---|---|
[백준] 5549 행성 탐사 [Python, 파이썬] (0) | 2023.11.30 |
[백준] 28283 해킹 [Python, 파이썬] (0) | 2023.11.13 |
[VS Code가상환경] 파이썬 가상 환경 생성 (1) | 2023.11.12 |
[백준] 13975 파일 합치기 3 [Python, 파이썬] (0) | 2023.11.09 |
Comments