#include<bits/stdc++.h>
using namespace std;
priority_queue<int> pq;
int n, k, T[100100], ans;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> k;
for(int i = 1; i<=n; ++i) cin >> T[i];
sort(T+1, T+1+n);
k--;
for(int i = 2; i<=n; ++i) pq.push(T[i] - T[i - 1] - 1);
ans = T[n] - T[1] + 1;
while(k--){
ans-=pq.top();
pq.top();
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
456 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
456 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
456 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |