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;
#define int long long
int n, k, prev, cur, ans;
vector <int> gaps;
signed main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
cin>>n>>k;
int prev=0;
ans=n;
for (int i=0; i<n; i++){
int cur;
cin>>cur;
if ((cur-prev)!=1){
//cout<<cur-prev<<'\n';
gaps.push_back(cur-prev-1);
}
prev=cur;
}
int s=gaps.size();
//cout<<s<<'s';
sort(gaps.begin(), gaps.end());
for (int i=0; i<s-k+1; i++){
ans+=gaps[i];
}
cout<<ans;
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... |