n, k = [ int(x) for x in input().split() ]
a = []
for i in range(n):
a.append( int(input()) )
a.sort()
t = a[n-1]+1-a[0]
#print(t)
diff = []
for i in range(0,n-1):
diff.append( a[i+1] - (a[i]+1) )
diff.sort()
diff.reverse()
#print( diff )
for i in range( min( n-1, k-1 ) ):
t -= diff[i]
print( t )
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
2772 KB |
Output is correct |
2 |
Correct |
13 ms |
2780 KB |
Output is correct |
3 |
Correct |
13 ms |
2812 KB |
Output is correct |
4 |
Correct |
13 ms |
2732 KB |
Output is correct |
5 |
Correct |
12 ms |
2808 KB |
Output is correct |
6 |
Correct |
13 ms |
2772 KB |
Output is correct |
7 |
Correct |
13 ms |
2848 KB |
Output is correct |
8 |
Correct |
14 ms |
2848 KB |
Output is correct |
9 |
Correct |
13 ms |
2788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
2772 KB |
Output is correct |
2 |
Correct |
13 ms |
2780 KB |
Output is correct |
3 |
Correct |
13 ms |
2812 KB |
Output is correct |
4 |
Correct |
13 ms |
2732 KB |
Output is correct |
5 |
Correct |
12 ms |
2808 KB |
Output is correct |
6 |
Correct |
13 ms |
2772 KB |
Output is correct |
7 |
Correct |
13 ms |
2848 KB |
Output is correct |
8 |
Correct |
14 ms |
2848 KB |
Output is correct |
9 |
Correct |
13 ms |
2788 KB |
Output is correct |
10 |
Correct |
17 ms |
3156 KB |
Output is correct |
11 |
Correct |
18 ms |
3108 KB |
Output is correct |
12 |
Correct |
18 ms |
3156 KB |
Output is correct |
13 |
Correct |
20 ms |
3152 KB |
Output is correct |
14 |
Correct |
22 ms |
3116 KB |
Output is correct |
15 |
Correct |
19 ms |
3020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
2772 KB |
Output is correct |
2 |
Correct |
13 ms |
2780 KB |
Output is correct |
3 |
Correct |
13 ms |
2812 KB |
Output is correct |
4 |
Correct |
13 ms |
2732 KB |
Output is correct |
5 |
Correct |
12 ms |
2808 KB |
Output is correct |
6 |
Correct |
13 ms |
2772 KB |
Output is correct |
7 |
Correct |
13 ms |
2848 KB |
Output is correct |
8 |
Correct |
14 ms |
2848 KB |
Output is correct |
9 |
Correct |
13 ms |
2788 KB |
Output is correct |
10 |
Correct |
17 ms |
3156 KB |
Output is correct |
11 |
Correct |
18 ms |
3108 KB |
Output is correct |
12 |
Correct |
18 ms |
3156 KB |
Output is correct |
13 |
Correct |
20 ms |
3152 KB |
Output is correct |
14 |
Correct |
22 ms |
3116 KB |
Output is correct |
15 |
Correct |
19 ms |
3020 KB |
Output is correct |
16 |
Correct |
201 ms |
12228 KB |
Output is correct |
17 |
Correct |
201 ms |
12248 KB |
Output is correct |
18 |
Correct |
197 ms |
12128 KB |
Output is correct |
19 |
Correct |
197 ms |
12128 KB |
Output is correct |
20 |
Correct |
208 ms |
12064 KB |
Output is correct |
21 |
Correct |
210 ms |
12072 KB |
Output is correct |
22 |
Correct |
219 ms |
12100 KB |
Output is correct |
23 |
Correct |
219 ms |
12080 KB |
Output is correct |
24 |
Correct |
218 ms |
12128 KB |
Output is correct |