from bisect import bisect_left, bisect_right
from heapq import heappush, heappop, heapify
from math import *
from collections import defaultdict, Counter, deque
from sys import stdin, stdout
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
ninput = lambda: int(input())
sinput = lambda: input().decode().strip()
ainput = lambda: list(map(int, input().split()))
printt = lambda *x: stdout.write(" ".join(map(str, x)) + '\n')
ceil = lambda a, b: a // b if (a >= 0) ^ (b > 0) else (abs(a) + abs(b) - 1) // abs(b)
t = 1
for _ in range(t):
n, k = ainput()
t = [ninput() for _ in range(n)]
diff = [t[i] - t[i-1] for i in range(1, n)]
diff.sort()
summ = 0
while k - 1: summ += (diff.pop() - 1); k -= 1
printt((t[-1] - t[0] + 1) - summ)
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
18804 KB |
Output is correct |
2 |
Correct |
36 ms |
18716 KB |
Output is correct |
3 |
Correct |
36 ms |
18816 KB |
Output is correct |
4 |
Correct |
35 ms |
18784 KB |
Output is correct |
5 |
Correct |
36 ms |
18712 KB |
Output is correct |
6 |
Correct |
39 ms |
18732 KB |
Output is correct |
7 |
Correct |
36 ms |
18732 KB |
Output is correct |
8 |
Correct |
36 ms |
18780 KB |
Output is correct |
9 |
Correct |
36 ms |
18784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
18804 KB |
Output is correct |
2 |
Correct |
36 ms |
18716 KB |
Output is correct |
3 |
Correct |
36 ms |
18816 KB |
Output is correct |
4 |
Correct |
35 ms |
18784 KB |
Output is correct |
5 |
Correct |
36 ms |
18712 KB |
Output is correct |
6 |
Correct |
39 ms |
18732 KB |
Output is correct |
7 |
Correct |
36 ms |
18732 KB |
Output is correct |
8 |
Correct |
36 ms |
18780 KB |
Output is correct |
9 |
Correct |
36 ms |
18784 KB |
Output is correct |
10 |
Correct |
42 ms |
19632 KB |
Output is correct |
11 |
Correct |
53 ms |
19588 KB |
Output is correct |
12 |
Correct |
41 ms |
19652 KB |
Output is correct |
13 |
Correct |
44 ms |
19848 KB |
Output is correct |
14 |
Correct |
42 ms |
19712 KB |
Output is correct |
15 |
Correct |
42 ms |
19708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
18804 KB |
Output is correct |
2 |
Correct |
36 ms |
18716 KB |
Output is correct |
3 |
Correct |
36 ms |
18816 KB |
Output is correct |
4 |
Correct |
35 ms |
18784 KB |
Output is correct |
5 |
Correct |
36 ms |
18712 KB |
Output is correct |
6 |
Correct |
39 ms |
18732 KB |
Output is correct |
7 |
Correct |
36 ms |
18732 KB |
Output is correct |
8 |
Correct |
36 ms |
18780 KB |
Output is correct |
9 |
Correct |
36 ms |
18784 KB |
Output is correct |
10 |
Correct |
42 ms |
19632 KB |
Output is correct |
11 |
Correct |
53 ms |
19588 KB |
Output is correct |
12 |
Correct |
41 ms |
19652 KB |
Output is correct |
13 |
Correct |
44 ms |
19848 KB |
Output is correct |
14 |
Correct |
42 ms |
19712 KB |
Output is correct |
15 |
Correct |
42 ms |
19708 KB |
Output is correct |
16 |
Correct |
62 ms |
23616 KB |
Output is correct |
17 |
Correct |
63 ms |
23640 KB |
Output is correct |
18 |
Correct |
63 ms |
23560 KB |
Output is correct |
19 |
Correct |
63 ms |
23764 KB |
Output is correct |
20 |
Correct |
62 ms |
23716 KB |
Output is correct |
21 |
Correct |
78 ms |
23940 KB |
Output is correct |
22 |
Correct |
69 ms |
23964 KB |
Output is correct |
23 |
Correct |
64 ms |
24352 KB |
Output is correct |
24 |
Correct |
67 ms |
24396 KB |
Output is correct |