This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main () {
int n, k;
cin >> n >> k;
int t[n+1], d[n];
t[0] = 0;
for(int i = 1;i<=n;i++) {
cin >> t[i];
d[i-1] = t[i] - t[i-1] - 1;
}
int Max = t[n]+1, Min = t[1];
int ans = Max - Min;
sort(d, d+n);
reverse(d, d+n);
for(int i = 0;i<min(n, k-1);i++)ans-=d[i];
cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |