#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
int n, k; cin >> n >> k;
vector<int> v(n);
for(auto &x : v) cin >> x;
priority_queue<int> pq;
for(int i = 1; i < n; ++i){
pq.push(v[i] - v[i - 1] - 1);
}
int ans = v.back();
for(int i = 1; i < k; ++i){
ans -= pq.top();
pq.pop();
}
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |