[알고리즘/백준] 14241번 : 슬라임 합치기(python)

유현민·2022년 3월 15일
0

알고리즘

목록 보기
52/253

정렬해주고 계산하면 된다...

N = int(input())
a = sorted(list(map(int, input().split())))
tmp = 0
score = 0
for i in range(1, N):
    if i == 1:
        tmp = a[i-1] + a[i]
        score = a[i-1] * a[i]
    else:
        score += tmp * a[i]
        tmp += a[i]


print(score)
profile
smilegate megaport infra

0개의 댓글