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 int mxn = 2e5+5;
ll arr[mxn];
int main()
{
int n, k;
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> arr[i];
sort(arr+1, arr+n+1);
vector<ll>v;
ll sum = 0;
for(int i = 2; i <= n; i++) {
ll d = arr[i]-arr[i-1]-1;
v.push_back(arr[i]-arr[i-1]-1);
sum+=d;
}
sort(v.rbegin(), v.rend());
/*
for(auto it : v) {
cout << it << ' ';
}
cout << '\n';
*/
int x = min((int)v.size(), k-1);
for(int i = 0; i < x; i++) {
sum-=v[i];
}
sum+=n;
cout << sum << '\n';
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... |