#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, k, prev, cur, ans;
vector <int> gaps;
signed main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
cin>>n>>k;
int prev=0;
ans=n;
for (int i=0; i<n; i++){
int cur;
cin>>cur;
if ((cur-prev)!=1){
//cout<<cur-prev<<'\n';
gaps.push_back(cur-prev-1);
}
prev=cur;
}
int s=gaps.size();
//cout<<s<<'s';
sort(gaps.begin(), gaps.end());
for (int i=0; i<s-k+1; i++){
ans+=gaps[i];
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 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 |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |