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() {
int n, k, l=-1; cin>>n>>k;
vector<int> v;
int ans=0, mn=1e9+1, mx=-1e9-1;
for (int i=1; i<=n; ++i) {
int a; cin>>a;
mn=min(mn, a), mx=max(mx, a);
if (l != -1) v.push_back(a-l-1);
l=a;
}
ans=mx-mn+1;
sort(v.begin(), v.end(), greater<int>());
for (int i=0; i<min((int)v.size(), k-1); ++i) ans-=v[i];
cout<<ans<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |