This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n,k,T[100010],ans;
vector<int> V;
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n>>k;
for(int i=1; i<=n; i++) cin>>T[i];
sort(T+1, T+n+1);
for(int i=1; i<=n; i++) if(T[i]!=T[i-1]) ans++;
for(int i=1; i<n; i++)
if(T[i+1]>T[i]+1) V.push_back(T[i+1]-T[i]-1);
sort(V.begin(), V.end());
for(int i=0; i<(int)V.size()-(k-1); i++) ans+=V[i];
cout<<ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |