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;
#define int long long
#define all(x) x.begin(), x.end()
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
int n,k;cin>>n>>k;vector<int>a(n);for(auto&i:a)cin>>i;
sort(all(a));
vector<int>d;for(int i=1;i<n;i++)d.push_back(max(0ll,a[i]-a[i-1]-1));
sort(all(d)); reverse(all(d));
int sub=0;for(int i=0;i<min(k-1,n-1);i++)sub+=d[i];
cout<<a.back()-a[0]-sub+1<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |