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], d[n];
for(int i = 0;i<n;i++) {
cin >> t[i];
}
for(int i = 0;i<n-1;i++)d[i] = t[i+1] - t[i] - 1;
int ans =t[n-1] - t[0] + 1;
sort(d, d+n, greater<int>());
for(int i = 1;i<k;i++)ans-=d[i-1];
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... |