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<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, k;
cin >> n >> k;
vector<ll> v(n + 1);
for(ll i = 1; i <= n; ++i)
cin >> v[i];
vector<ll> diff(n);
for(ll i = 1; i < n; ++i)
diff[i] = v[i + 1] - v[i] - 1;
sort(diff.begin() + 1, diff.end(), greater<ll>());
ll ans = n;
for(ll i = k; i < n; ++i){
ans += diff[i];
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |