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;
int n,k,a[1000005],res=0;
vector<int> adj;
signed main()
{
cin>>n>>k;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(i>1) adj.push_back(a[i]-a[i-1]-1);
}
sort(adj.begin(),adj.end());
res=n;
for(int i=0;i<=n-k-1;i++) res=res+adj[i];
cout<<res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |