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>
#define int long long
using namespace std;
const int N = 1e5+5;
int n, k, a[N];
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>k;
for (int i=1; i<=n; i++) cin>>a[i];
sort(a+1, a+1+n);
int sum = a[n] - a[1] + 1;
vector <int> v; v.clear();
for (int i=2; i<=n; i++)
v.push_back(a[i]-a[i-1]-1);
sort(v.begin(), v.end());
for (int i=1; i<k; i++) sum-=v[(v.size()-i)];
cout<<sum;
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... |