This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//required macros and template
#include <bits/stdc++.h>
using namespace std;
//type definitions
#define vc vector
typedef vc<int> vi;
//main method
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k, ans;
cin>>n>>k;
ans = n;
vi t(n), x;
for(int i = 0; i<n; i++) {
cin >> t[i];
if(i and t[i]!=t[i-1]+1)
x.push_back(t[i]-t[i-1]-1);
}
sort(x.begin(), x.end());
for(int i = x.size()-k; i>=0; i--)
ans += x[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... |