[Greedy] 15903번 - 카드 합체 놀이(39일차)

bob.sort·2021년 6월 29일
0
post-thumbnail
#코드 실행 시간 단축
import sys
input = sys.stdin.readline
#카드의 개수, 카드 합체의 횟수 입력
n, m = map(int, input().split())
#각 카드의 숫자 입력 후 오름차순 정렬
card = sorted(list(map(int, input().split())))

#카드 합체의 횟수만큼
for i in range(m):
    #가장 작은 수와 2번째로 작은 수를 더해서
    temp = card[0] + card[1]
    #각 인덱스레 temp 값을 배치
    card[0] = temp
    card[1] = temp
    #업데이트된 카드의 숫자 기준으로 정렬
    card.sort()
    
#모든 카드 합체가 끝난 후 카드 숫자들의 합 출력
print(sum(card))
profile
Interest in Computer Graphics and Computer Vision

0개의 댓글