[백준] 14241번 슬라임 합치기

거북이·2023년 3월 18일
0

백준[실버3]

목록 보기
68/92
post-thumbnail

💡문제접근

  • 슬라임을 합쳐서 얻을 수 있는 점수의 최댓값을 구하는 문제다. 정렬을 수행해서 뒤의 큰 값 두 개를 가져와서 두 값을 더한 값을 다시 리스트에 추가하고 두 값을 곱한 값을 점수로 더해준다.

💡코드(메모리 : 31256KB, 시간 : 40ms)

import sys
input = sys.stdin.readline

score = 0
N = int(input())
li = list(map(int, input().strip().split()))
li.sort()

while True:
    if len(li) <= 1:
        break
    else:
        a = li.pop()
        b = li.pop()
        score += (a*b)
        li.append(a+b)
        li.sort()
print(score)

💡소요시간 : 7m

0개의 댓글