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;
const int N = 25;
int32_t main()
{
int n,k;
cin>>n>>k;
int a[n+1];
for(int i=1;i<=n;i++){
cin>>a[i];
}
int res = a[n] + 1 - a[1];
priority_queue<int>q;
for(int i=2;i<=n;i++){
q.push(a[i] - a[i-1] - 1);
}
k--;
while(k--){
res -= q.top();
q.pop();
}
cout<<res<<endl;
return 0;
}
/*
1 1 2 2 3 3 4 4
1
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |