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;
priority_queue<int> pq;
int a[111111];
int main()
{
int n,k;cin>>n>>k;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=2;i<=n;i++)
pq.push(a[i]-a[i-1]-1);
int ans=a[n];
int cnt=0;
while(cnt<k-1){
ans-=pq.top();
//cout<<pq.top()<<'\n';
pq.pop();
cnt++;
}
cout<<ans<<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |