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>
#define int long long
using namespace std;
signed main(){
int n ;
int k ;
cin>> n >>k ;
vector<int> a(n) ;
for(int& x : a) cin>>x ;
int ans = 0 ;
for(int i=1;i<n;i++) ans+=a[i]-a[i-1]-1 ;
vector<int> b ;
for(int i=1;i<n;i++){
b.push_back(a[i-1]-a[i]+1) ;
}
sort(b.begin(),b.end()) ;
for(int i=0;i<k-1;i++){
b[i]*=-1 ;
ans-=b[i] ;
}
cout << ans+n ;
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... |