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;
#define MAXN 100001
long long n,k;
long long a[MAXN];
vector<long long> raz;
int main()
{
cin>>n>>k;
for (long long i=1;i<=n;i++) cin>>a[i];
for (long long i=2;i<=n;i++) raz.push_back(a[i]-a[i-1]-1);
sort(raz.begin(),raz.end());
long long ans=n;
for (long long i=0;i<n-k;i++) ans+=raz[i];
cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |