๋ฌธ์
https://www.acmicpc.net/problem/1715
ํ์ด
# ๋ฐฑ์ค 1715๋ฒ ๋ฌธ์ - ์นด๋ ์ ๋ ฌํ๊ธฐ
import heapq
import sys
input = sys.stdin.readline
n = int(input())
cards = []
result = 0
for i in range(n):
heapq.heappush(cards, int(input()))
if len(cards) == 1:
print(0)
else:
while len(cards) > 1:
plus = heapq.heappop(cards) + heapq.heappop(cards)
result += plus
heapq.heappush(cards, plus)
print(result)
ํ ์๋ฃ๊ตฌ์กฐ๋ฅผ ์ฌ์ฉํ์ฌ ํ๋ฉด ๊ฐ๋จํ ๋ฌธ์ ์ด๋ค.
ํ ๋ฌธ์ ๋ฅผ ๋ง์ด ํ์ด๋ณด์ง ์์์ ์ฒ์์ ์๊ฐํ๋๋ฐ ์๊ฐ์ด ์ค๋ ๊ฑธ๋ ธ๋ค.
ํ ์๋ฃ๊ตฌ์กฐ์ ๋ํด ์ ๋ฆฌํ๋ ๊ธ์ ์ฐ๋๋ก ํด์ผ๊ฒ ๋ค.
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] 1744๋ฒ_์ ๋ฌถ๊ธฐ (0) | 2023.03.31 |
---|---|
๐ฉ [๋ฐฑ์ค] [Python] [Gold2] 1202๋ฒ_๋ณด์ ๋๋ (0) | 2023.03.30 |
๐ฉ [๋ฐฑ์ค] [Python] [Silver1] 11660๋ฒ_๊ตฌ๊ฐ ํฉ ๊ตฌํ๊ธฐ 5 (0) | 2023.03.25 |
๐ฉ [๋ฐฑ์ค] [Python] [Silver2] 18111๋ฒ_๋ง์ธํฌ๋ํํธ (0) | 2023.03.20 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold5] 11000๋ฒ_๊ฐ์์ค ๋ฐฐ์ (0) | 2023.03.19 |