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 <iostream>
#include <algorithm>
using namespace std;
int n,k,t[100010],ans;
int main()
{
cin>>n>>k;
for(int i=1;i<=n;++i)
cin>>t[i];
sort(t+1,t+n+1);
ans=t[n]+1-t[1];
for(int i=1;i<n;++i)
t[i]=t[i+1]-t[i]-1;
sort(t+1,t+n);
for(int i=n-1;i>0&&i>=n-k+1;--i)
ans-=t[i];
cout<<ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |