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;
using ll = long long;
#define MAXN (1000005)
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);
ll N,K;
cin>>N>>K;
ll arr[N];
for(ll i = 0;i < N;i++){
cin>>arr[i];
}
sort(arr,arr + N);
vector<ll> gap;
ll sum = N;
for(ll i = 1;i < N;i++){
gap.push_back(arr[i] - (arr[i - 1] + 1));
}
sort(gap.begin(),gap.end());
for(ll i = 0;i < N - K;i++){
sum += gap[i];
}
cout<<sum<<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |