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 endl '\n'
#define pb push_back
#define ll long long
#define int ll
const long long inf=1e18;
const int MOD=1e9+7;
const int N=2e5+5;
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,k; cin>>n>>k;
vector<int> v;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
if(i>0)v.pb(a[i]-a[i-1]-1);
}
int ans=a[n-1]-a[0]+1;
sort(v.begin(),v.end());
for(int i=n-2;i>=n-k;i--)ans-=v[i];
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |