#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
const int MX = 1e5 + 5;
int a[MX], sa = 0, n, k;
priority_queue < int > pq;
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> k;
for ( int i = 1; i <= n; i++ ){
cin >> a[i];
if ( i >= 2 ) pq.push(a[i] - a[i - 1] - 1);
sa += ( a[i] - a[i - 1] - 1 );
}
for ( int i = 1; i <= k - 1; i++ ){
sa -= pq.top(); pq.pop();
}
cout << sa + n << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |