#include<bits/stdc++.h>
#define int long long
#define ms(v) memset(v, -1, sizeof v)
#define pi pair<int, int>
#define pb push_back
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
#define INF 1e15
#define mp make_pair
#define itn int
#define N 100010
using namespace std;
int n, k;
int v[N];
int32_t main(){
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> k;
for(int i = 1;i <= n;i++){
cin >> v[i];
}
k--;
int res = v[n];
priority_queue <int> pq;
for(int i = 1;i <= n;i++){
pq.push(v[i] - v[i-1] - 1);
}
while(k != 0){
int x = pq.top();
pq.pop();
res -= x;
k--;
}
cout << res << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |