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