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 pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k; cin >> n >> k;
ll mn = 1e18, mx = -1e18;;
vector <ll> v(n);
for(ll &x: v){
cin >> x;
mn = min(mn, x);
mx = max(mx, x);
}
if(k >= n){
cout << n << "\n";
exit(0);
}
ll ans = mx - mn + 1;
priority_queue<int> pq;
for(int i = 0; i < n - 1; i++) pq.push(v[i+1]-v[i]+1);
k--;
while(k--) ans-= pq.top(), pq.pop();
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... |