코딩테스트/BOJ

[백준][브루트포스][순열] 10819.차이를 최대로

박소민 2024. 10. 1. 16:09
10819.차이를 최대로

 

  • 내 풀이
    • 문제를 바로 이해하지 못함
    • 식이 배열 순서를 바꾼거라는게 아니라 배열 순서를 바꾼 뒤에 식을 진행했을때의 최댓값
from itertools import permutations

n = int(input())
nums = sorted(list(map(int, input().split())))

ans = 0
for perm in (permutations(nums, n)):
    tmp = 0
    for i in range(1, n):
        tmp += abs(perm[i-1]-perm[i])

    ans = max(ans, tmp)

print(ans)