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 int long long
#define endl '\n'
const int sz = 1e6 + 5;
long long a[sz];
int n, k;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("main.inp","r",stdin);
//freopen("main.out","w",stdout);
cin >> n >> k;
if(k == n){
cout << n;
return 0;
}
vector<int> v;
for(int i=1;i<=n;++i){
cin >> a[i];
if(i > 1){
v.push_back(a[i] - a[i-1] - 1);
}
}
sort(v.begin(), v.end(), greater<int>());
long long ans = a[n] - a[1] + 1;
for(int i=0;i<k-1;++i){
ans -= (v[i]);
}
cout << ans;
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... |