목차

행복 유치원

ps
링크acmicpc.net/…
출처BOJ
문제 번호13164
문제명행복 유치원
레벨골드 5
분류

그리디

시간복잡도O(nlogn)
인풋사이즈n<=300,000
사용한 언어Python
제출기록65852KB / 268ms
최고기록268ms
해결날짜2022/01/26

풀이

코드

"""Solution code for "BOJ 13164. 행복 유치원".

- Problem link: https://www.acmicpc.net/problem/13164
- Solution link: http://www.teferi.net/ps/problems/boj/13164

Tags: [Greedy]
"""

import itertools


def main():
    N, K = [int(x) for x in input().split()]  # pylint: disable=unused-variable
    heights = [int(x) for x in input().split()]

    diffs = [b - a for a, b in itertools.pairwise(heights)]
    print(sum(sorted(diffs)[:N - K]))


if __name__ == '__main__':
    main()