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