#include <bits/stdc++.h>
using namespace std;
int main () {
int n, k;
cin >> n >> k;
int t[n+1];
for (int i = 1; i <= n; i++) {
cin >> t[i];
}
int mx = t[n] - t[1] + 1;
vector<int> dif;
for (int i = 1; i < n; i++) {
dif.push_back(t[i+1] - t[i] - 1);
}
sort(dif.begin(), dif.end());
for (int i = 0; i < min((int)dif.size(), k); i++) {
mx -= dif[i];
}
cout << mx;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |