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,ans;
int v[100005];
multiset<int> s;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>k;
for(int i=1;i<=n;i++)
cin>>v[i];
ans=v[n]+1-v[1];
k--;
for(int i=2;i<=n;i++)
s.insert(v[i]-v[i-1]-1);
while(k)
{
k--;
auto it = prev(s.end());
ans -= *it;
s.erase(it);
}
cout<<ans<<'\n';
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... |