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
signed main(){
int n,k;
cin>>n>>k;
int a[n+1];
for(int q=1;q<=n;q++){
cin>>a[q];
}
vector<int>cek;
for(int q=1;q<n;q++){
int has=a[q+1]-a[q]-1;
cek.push_back(has);
}
int ans=a[n]-a[1]+1;
sort(cek.rbegin(),cek.rend());
for(int q=0;q<k-1;q++){
ans-=cek[q];
}
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... |