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>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
const int N=1e5+50;
int a[N],d[N];
int n,k,ans;
signed main(){
// freopen(".inp","r",stdin);
// freopen(".out","w",stdout);
// ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n>>k;
ans=n;
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n-1;i++) d[i]=a[i+1]-a[i]-1;
sort(d,d+n-1);
for(int i=0;i<n-k;i++) ans+=d[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... |