This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In the name of Allah. Ya ali!
#include<bits/stdc++.h>
#define double long double
typedef long long ll;
const ll MAX_N = 1e5+10;
const ll MOD = 1e9+7;
using namespace std;
int a[MAX_N];
int n,k;
ll ans;
int main()
{
cin >> n >> k;
for(int i = 1;i<=n;++i)
cin >> a[i];
ans = n;
vector<int> vc;
sort(a+1,a+n+1);
for(int i = 2;i<=n;++i)
vc.push_back(a[i]-a[i-1]-1);
sort(vc.begin(),vc.end());
for(int i = 0;i<n-k;++i)
ans += vc[i];
cout << ans;
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... |