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 ff first
#define ss second
using namespace std;
const int N=5e5+1;
int main()
{
ll n , k;
cin >> n >> k ;
ll arr[n+1];
ll v[n+1];
for (int i=0;i<n;i++)
{
cin >> arr[i];
if(i!=0)
{
v[i-1]=arr[i]-arr[i-1]-1;
}
}
sort(v,v+n-1);
ll ans=n;
for (int i=0;i<n-k;i++)
{
ans+=v[i];
}
cout<<ans<<"\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... |