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 ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll n,k,i,a[101010],has;
vector<ll> v;
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>k;
for(i=1;i<=n;i++)
cin>>a[i];
for(i=1;i<n;i++)
v.pb(a[i+1]-a[i]-1);
sort(v.begin(),v.end());
for(i=0;i<n-k;i++)
has+=v[i];
has+=n;
cout<<has<<"\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... |