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;
typedef long long ll;
const ll num=(1e9)+7;
const ll N=4*(1e5)+10;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n, k, i;
cin>>n>>k;
vector<ll> t(n);
for(i=0; i<n; i++){
cin>>t[i];
}
sort(t.begin(), t.end());
vector<ll> v;
for(i=1; i<n; i++){
v.push_back(t[i]-t[i-1]-1);
}
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
ll l=t[n-1]+1-t[0];
for(i=0; i<k-1; i++){
l-=v[i];
}
cout<<l;
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... |