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;
typedef long long int ll;
const int MOD = 1e9 + 7;
void solve(){
int n, k; cin >> n >> k;
vector<int> v(n - 1);
int lst = -1;
for(int i = 0; i < n; i++){
int x; cin >> x;
if(i == 0){lst = x; continue;}
v[i - 1] = x - lst - 1; lst = x;
}
sort(v.begin(), v.end());
int curr = n;
ll ans = n;
for(int i = 0; i < n - 1 && curr > k; i++){
ans += v[i]; curr--;
}
cout << ans << endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//~ int tt; cin >> tt;
int tt = 1;
for(int t = 1; t <= tt; t++){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |