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;
cin >> n >> k;
vector<int> v(n);
for(int &i : v)
cin >> i;
if(k == 1){
cout << v.back() + 1 - v.front() << "\n";
return 0;
}
// int div = ceil(n/2);
// biz aralaryny yakynlasdyrjak bolyas
int ans = v.back() + 1 - v.front();
vector<int> tap;
for(int i = 0; i < n - 1; ++i){
int diff = abs(v[i + 1] - v[i]);
tap.push_back(diff);
}
k--;
sort(tap.rbegin(), tap.rend());
for(int i = 1; i <= k; ++i){
ans -= tap[i - 1];
ans++;
}
// ans += k;
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... |