10819번 – 차이를 최대로

문제

https://www.acmicpc.net/problem/10819

풀이

코드

from itertools import permutations

def answer():
  global n, arr
  perms = list(permutations(arr, len(arr)))
  maxArr = []
  for case in perms:
    diffSum = 0
    for i in range(1, len(case)):
      diffSum += abs(case[i] - case[i-1])
    maxArr.append(diffSum)
  print(max(maxArr))

n = int(input())
arr = list(map(int, input().split()))
answer()

Leave a Reply

Your email address will not be published.