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 main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, k,ans=0;
cin>>n>>k;
int a[n];
int b[n-1];
int dif = n-k;
ans=n;
//avoid biggest gaps
for(int i=0;i<n;i++){
cin>>a[i];
if(i!=0){
b[i-1]=a[i]-a[i-1]-1;
}
}
sort(b,b+n-1);
for(int i=0;i<dif;i++){
ans+=b[i];
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |