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 FOR(i, a, b) for(int i = a; i < b; i++)
int main(){
int n, k; cin >> n >> k;
vector<int> t(n); FOR(i, 0, n) cin >> t[i];
int ans = t[n-1] + 1 - t[0];
vector<int> d(n-1);
FOR(i, 0, n-1){
d[i] = t[i+1] - t[i] - 1;
}
sort(d.begin(), d.end());
FOR(i, n-k, n-1){
ans -= d[i];
}
cout << ans << '\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... |