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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, k;
cin>>n>>k;
vector<long long> vect(n);
for (long long i=0;i<n;i++) cin>>vect[i];
sort(vect.begin(), vect.end());
vector<long long> diffs(n-1);
for (long long i=0;i<n-1;i++){
diffs[i]=vect[i+1]-vect[i]-1;
}
sort(diffs.begin(), diffs.end());
long long out=n;
for (long long i=0;i<n-k;i++) out+=diffs[i];
cout<<out<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |