#include <bits/stdc++.h>
#define For(i,a,n) for (int i = a; i < n; i++)
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k;
cin >> n >> k;
vector<int> t(n), gap(n - 1);
For(i,0,n) cin >> t[i];
For(i,0,n - 1){
gap[i] = t[i + 1] - t[i] - 1;
}
sort(gap.begin(), gap.end());
int ans = t[n - 1] - t[0] + 1;
if(k >= n) cout << n;
else{
if(k > 1){
For(i,1,k){
ans -= gap[n - i - 1];
}
}
cout << ans;
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |