n,k=map(int,input().split())
mas=[]
dif=[]
for i in range(n):
mas.append(int(input()))
if len(mas)>=2:
dif.append([mas[-1]-mas[-2],i])
dif.sort(key=lambda x:x[0],reverse=True)
if n==k:
print(n)
elif k==1:
print(mas[-1]+1-mas[0])
else:
c=0
ind=[0]
for i in range(k-1):
ind.append(dif[i][1])
ind.append(n)
ind.sort()
for i in range(1,len(ind)):
c+=mas[ind[i]-1]+1-mas[ind[i-1]]
print(c)
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2908 KB |
Output is correct |
2 |
Correct |
8 ms |
2808 KB |
Output is correct |
3 |
Correct |
8 ms |
2908 KB |
Output is correct |
4 |
Correct |
9 ms |
2908 KB |
Output is correct |
5 |
Correct |
9 ms |
2908 KB |
Output is correct |
6 |
Correct |
8 ms |
2908 KB |
Output is correct |
7 |
Correct |
9 ms |
2908 KB |
Output is correct |
8 |
Correct |
12 ms |
2948 KB |
Output is correct |
9 |
Correct |
9 ms |
3008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2908 KB |
Output is correct |
2 |
Correct |
8 ms |
2808 KB |
Output is correct |
3 |
Correct |
8 ms |
2908 KB |
Output is correct |
4 |
Correct |
9 ms |
2908 KB |
Output is correct |
5 |
Correct |
9 ms |
2908 KB |
Output is correct |
6 |
Correct |
8 ms |
2908 KB |
Output is correct |
7 |
Correct |
9 ms |
2908 KB |
Output is correct |
8 |
Correct |
12 ms |
2948 KB |
Output is correct |
9 |
Correct |
9 ms |
3008 KB |
Output is correct |
10 |
Correct |
13 ms |
3420 KB |
Output is correct |
11 |
Correct |
13 ms |
3420 KB |
Output is correct |
12 |
Correct |
13 ms |
3576 KB |
Output is correct |
13 |
Correct |
15 ms |
3576 KB |
Output is correct |
14 |
Correct |
15 ms |
3580 KB |
Output is correct |
15 |
Correct |
14 ms |
3480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2908 KB |
Output is correct |
2 |
Correct |
8 ms |
2808 KB |
Output is correct |
3 |
Correct |
8 ms |
2908 KB |
Output is correct |
4 |
Correct |
9 ms |
2908 KB |
Output is correct |
5 |
Correct |
9 ms |
2908 KB |
Output is correct |
6 |
Correct |
8 ms |
2908 KB |
Output is correct |
7 |
Correct |
9 ms |
2908 KB |
Output is correct |
8 |
Correct |
12 ms |
2948 KB |
Output is correct |
9 |
Correct |
9 ms |
3008 KB |
Output is correct |
10 |
Correct |
13 ms |
3420 KB |
Output is correct |
11 |
Correct |
13 ms |
3420 KB |
Output is correct |
12 |
Correct |
13 ms |
3576 KB |
Output is correct |
13 |
Correct |
15 ms |
3576 KB |
Output is correct |
14 |
Correct |
15 ms |
3580 KB |
Output is correct |
15 |
Correct |
14 ms |
3480 KB |
Output is correct |
16 |
Correct |
141 ms |
23440 KB |
Output is correct |
17 |
Correct |
141 ms |
23460 KB |
Output is correct |
18 |
Correct |
141 ms |
23520 KB |
Output is correct |
19 |
Correct |
170 ms |
23408 KB |
Output is correct |
20 |
Correct |
162 ms |
23596 KB |
Output is correct |
21 |
Correct |
183 ms |
23456 KB |
Output is correct |
22 |
Correct |
191 ms |
23512 KB |
Output is correct |
23 |
Correct |
185 ms |
23456 KB |
Output is correct |
24 |
Correct |
194 ms |
23520 KB |
Output is correct |