| ps | |
|---|---|
| 링크 | acmicpc.net/… |
| 출처 | BOJ |
| 문제 번호 | 2212 |
| 문제명 | 센서 |
| 레벨 | 골드 5 |
| 분류 |
그리디 |
| 시간복잡도 | O(nlogn) |
| 인풋사이즈 | n<=10000 |
| 사용한 언어 | Python |
| 제출기록 | 30864KB / 72ms |
| 최고기록 | 56ms |
| 해결날짜 | 2022/01/27 |
"""Solution code for "BOJ 2212. 센서".
- Problem link: https://www.acmicpc.net/problem/2212
- Solution link: http://www.teferi.net/ps/problems/boj/2212
Tags: [Greedy]
"""
import itertools
def main():
N = int(input())
K = int(input())
censors = [int(x) for x in input().split()]
diffs = [b - a for a, b in itertools.pairwise(sorted(censors))]
print(sum(sorted(diffs)[:N - K]))
if __name__ == '__main__':
main()