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