[백준] 10819번 차이를 최대로

거북이·2023년 1월 26일
0

백준[실버2]

목록 보기
21/81
post-thumbnail

💡문제접근

  • 모든 순열을 하나하나 비교해서 최댓값을 구했다.

💡코드(메모리 : 34896KB, 시간 : 144ms)

from itertools import permutations
import sys
input = sys.stdin.readline

N = int(input().strip())
A = list(map(int, input().strip().split()))

li = list(permutations(A, N))

max = -10000
for i in li:
    val = 0
    for j in range(len(i)-1):
        val += abs(i[j] - i[j+1])
    if max < val:
        max = val
print(max)

💡소요시간 : 4m

0개의 댓글