← Back to List

2212번: 센서 ↗

Solutions

Python 3
218 B | 218 chars
n = int(input())
k = int(input())

sensors = sorted(list([*map(int,input().split())]))

diffs = sorted([sensors[i] - sensors[i-1] for i in range(1,len(sensors))])

print(sum(diffs[:(len(diffs) if k == 1 else 1 - k)]))