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 main()
{
int n,k;
cin>>n>>k;
vector<long long> t;
for(int i = 0;i<n;i++)
{
long long x;
cin>>x;
t.push_back(x);
}
vector<long long> t2;
for(int i = 1;i<n;i++)
{
t2.push_back(t[i]-t[i-1]-1);
}
sort(t2.begin(),t2.end());
long long ans = n;
for(int i = 0;i<n-k;i++)
{
ans+=t2[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... |