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 f first
#define s second
#define pb push_back
using namespace std;
const int N=3e5+5;
long long a[N],n,k,ans;
vector <long long> v;
int main() {
cin>>n>>k;
for (int i=1; i<=n; i++) {
cin>>a[i];
}
// if (n==k) {
//cout<<k<<endl;
//return 0;
// }
for (int i=1; i<n; i++) {
v.pb(a[i]-a[i+1]);
}
sort(v.begin(), v.end());
// reverse(v.begin(),v.end());
for(int i=0; i<min(int(v.size()),int(k-1)); i++) {
ans+=v[i];
}
ans+=(a[n]+1-a[1])+(k-1);
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... |