이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
# ======== 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... |