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 ll long long int
int main()
{
ll n, k;
cin >> n >> k;
vector<ll> v(n), d;
for(ll i = 0;i<n;i++){
cin >> v[i];
if(i != 0)d.push_back(v[i] - v[i-1]);
}
sort(d.begin(), d.end(), greater<ll>());
ll ans = v[n-1] - v[0] + k;
for(ll i = 0;i<k-1;i++){
ans -= d[i];
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |