#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main () {
int n, k;
cin >> n >> k;
vector<int> v(n), res(n - 1);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
for (int i = 1; i < n; i++) {
res[i - 1] = v[i] - v[i - 1] - 1;
}
sort(res.begin(), res.end(), greater<int>());
int cost = 0;
for (int i = 0; i < k - 1; i++) {
cost += res[i];
}
cout << max(n, *max_element(v.begin(), v.end()) - cost) << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
440 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
440 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
440 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |