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 a[(int)1e5+4];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,k;
cin>>n>>k;
for(int i=0;i<n;++i)
cin>>a[i];
vector<int>d;
for(int i=1;i<n;++i)
d.push_back(a[i]-a[i-1]-1);
sort(d.rbegin(),d.rend());
int t=a[n-1]-a[0]+1;
for(int i=0;i<k-1;++i)
t-=d[i];
cout<<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... |