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;
#define int long long int
#define pb push_back
#define st first
#define nd second
#define lb lower_bound
const int N = 4000050;
int n, k, a, b, mak, mina;
priority_queue<int > v;
int32_t main(){
cin >> n >> k;
k--;
cin >> b;
mak = b;
mina = b;
for (int i = 1; i < n; i++){
cin >> a;
v.push(a-b);
// cout << a-b << endl;
b = a;
mak = max(a, mak);
mina = min(a, mina);
}
while(k > 0){
k--;
mak -= (v.top()-1);
v.pop();
}
cout << mak-mina+1 << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |