This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
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 )
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |