[알고리즘/백준] 10819번 : 차이를 최대로(python)

유현민·2022년 3월 16일
0

알고리즘

목록 보기
62/253

처음에는 최대 - 최소 이렇게 생각했는데 틀렸다... 순열을 이용해서 모든 경우를 다 계산해야한다.

from itertools import permutations
N = int(input())
a = sorted(list(map(int, input().split())))

case = list(permutations(a))

ans = 0
for i in case:
    tmp = 0
    for j in range(N - 1):
        tmp += abs(i[j] - i[j + 1])
    ans = max(tmp, ans)

print(ans)
profile
smilegate megaport infra

0개의 댓글