This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Dedicated to my love, ivaziva
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ar array
#define dbg(x) cerr << #x << ": " << x << "\n";
const int mxN=1e5+1;
ll n, k, a[mxN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k; --k;
vector<ll> b;
for(ll i=1; i<=n; ++i) cin >> a[i];
ll ans=a[n]-a[1];
for(ll i=2; i<=n; ++i) {
b.push_back(a[i]-a[i-1]-1);
}
sort(b.begin(), b.end(), greater<int>());
for(int i=0; i<k; ++i) {
ans-=b[i];
}
cout << ans+1 << "\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... |