🐍 Python/백준

[10819]차이를 최대로

Jayden1116 2022. 2. 18. 23:32
import sys
from itertools import permutations

N = int(sys.stdin.readline())

arr = list(map(int, sys.stdin.readline().rstrip().split()))

ans = 0

for i in permutations(arr, N):
    sum=0
    for j in range(N-1):
        sum += abs(i[j] - i[j+1])
        if sum > ans :
            ans = sum

print(ans)

itertools에서 순열 및 조합 가져오는 것 알아두기

10819 차이를 최대로