백준 문제 풀이
백준 10819 파이썬 python : 차이를 최대로 @@황소처럼 우직하게@@ 볼륨 쵀돼료!
hjp845
2020. 2. 28. 07:08
반응형
import sys
input = sys.stdin.readline
n = int(input())
lst = list(map(int, input().split()))
lst.sort()
def next_permutation(lst):
n = len(lst)
i = n - 1
while i > 0 and lst[i - 1] >= lst[i]:
i -= 1
if i == 0:
return [-1]
# i - 1
j = n - 1
while lst[j] <= lst[i - 1]:
j -= 1
tmp = lst[j]
lst[j] = lst[i - 1]
lst[i - 1] = tmp
lst = lst[:i] + sorted(lst[i:])
return lst
def get_value(lst):
total = 0
for i in range(len(lst) - 1):
total += abs(lst[i] - lst[i + 1])
return total
ans = -999999999
while True:
if lst == [-1]:
break
value = get_value(lst)
if ans < value:
ans = value
lst = next_permutation(lst)
print(ans)
222쵀돼료!!ㅊ
반응형