그리디, 정렬
import sys
import itertools
from collections import deque
n,k= map(int, sys.stdin.readline().split())
lis = list(map(int, sys.stdin.readline().split()))
cha = []
for i in range(1,n) :
cha.append(lis[i]-lis[i-1])
cha.sort()
for j in range(k-1) :
cha.pop()
print(sum(cha))
(1) 4프로에서 틀리는 풀이
import sys
import itertools
n,k= map(int, sys.stdin.readline().split())
lis = list(map(int, sys.stdin.readline().split()))
comb = itertools.combinations(lis, k )
mini = 999999999999999999999999999999
for i in comb:
res = 0
for j in range(len(i)-1, 0, -1):
res+=i[j]-i[j-1]
if mini>res:
mini = res
print(mini)