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 maxn 100005
using namespace std;
int n,k;
long long t[maxn];
vector<long long>v;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>n>>k;
k--;
for(int i=0;i<n;i++)cin>>t[i];
for(int i=1;i<n;i++)v.push_back(t[i]-t[i-1]-1);
sort(v.begin(),v.end());
long long sol=t[n-1]+1-t[0];
int sz=v.size();
for(int i=sz-1;k>0;i--)
{
sol-=v[i];
k--;
}
cout<<sol<<endl;
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... |