#include<iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
vector<int> vec(n);
for (int i=0;i<n;i++){
cin>>vec[i];
}
sort(vec.begin(),vec.end());
vector<int> intervals;
for (int i=1;i<n;i++){
if (vec[i]-vec[i-1]-1>0){
intervals.push_back(vec[i]-vec[i-1]-1);
}
}
sort(intervals.begin(),intervals.end());
if ((int)intervals.size()<k){
cout<<n<<"\n";
} else{
int ans=0;
for (int i=0;i<n-k;i++){
ans+=intervals[i];
}
cout<<(n+ans)<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |