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;
int n, k;
long long t[200000];
vector<long long> dist;
long long sum=0;
int main()
{
cin>>n>>k;
for (int i=0; i<n; i++){
cin>>t[i];
}
sum=t[n-1]-t[0]+1;
if (k==1){
cout<<t[n-1]-t[0]+1;
}
else {
for (int i=1; i<n; i++){
dist.push_back(t[i]-t[i-1]-1);
}
sort(dist.begin(), dist.end());
reverse(dist.begin(), dist.end());
for (int i=0; i<k-1; i++){
sum-=dist[i];
}
cout<<sum;
}
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... |