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;
void solve(){
int n, k;
cin>>n>>k;
multiset<int> d;
k = min(k-1, n-1);
int mn=1e9, mx=0;
int ls = -1;
for(int i=1; i<=n; i++){
int x;
cin>>x;
mn = min(mn, x);
mx = max(mx, x);
if(ls != -1) d.insert(x - ls-1);
ls = x;
}
int ans = mx - mn + 1;
while(k--){
auto it = *d.rbegin();
ans -= it;
d.erase(d.find(it));
//cout<<it<<'\n';
}
cout<<ans;
}
int main(){
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |