This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
# ======== author: kuanc (@kuantweets) | created: 05/11/22 01:25:10 ======== #
from sys import setrecursionlimit, stdin, stdout, stderr
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
from itertools import accumulate, combinations, permutations, product
from functools import lru_cache, cmp_to_key, reduce
from heapq import heapify, heappush, heappop, heappushpop, heapreplace
# from pypyjit import set_param
# set_param("max_unroll_recursion=-1")
# setrecursionlimit(300005)
INF = 1 << 60
MOD = 998244353 + 1755654
input = lambda: stdin.readline().rstrip("\r\n")
dbg = lambda *A, **M: stderr.write("\033[91m" + \
M.get("sep", " ").join(map(str, A)) + M.get("end", "\n") + "\033[0m")
# ============================ START OF MY CODE ============================ #
def solve(_tc):
N, K = map(int, input().split())
K -= 1
pq = []
prev = 0
first = INF
for _ in range(N):
x = int(input())
if prev:
heappush(pq, -(x - prev))
first = min(first, x)
prev = x
ans = prev - first + 1
while pq and K:
x = -heappop(pq) - 1
ans -= x
K -= 1
print(ans)
if __name__ == "__main__":
# _tcs = int(input())
for _tc in range(1, vars().get("_tcs", 1) + 1):
dbg("=== Case {} ===".format(str(_tc).rjust(2)))
solve(_tc)
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |