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 ccd ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
using namespace std;
/* ------------------------ hi lol ------------------------ */
string s;
ll n,k,ans,arr[100'001];
priority_queue<ll> pq;
bool done=false;
int main() {
ccd
cin >> n >> k;
for (int i=1;i<=n;i++) {
cin >> arr[i];
if (i==1&&!done) {
if (arr[1]!=1) {
pq.push(arr[1]-1);
}
done=1;
}
if (i>1) {
if (arr[i]-arr[i-1]>1) {
pq.push(arr[i]-arr[i-1]-1);
}
}
}
ans=arr[n];
if (n==1) {
cout << ans-pq.top() << endl;
return 0;
}
k--;
// cout << ans << endl;
// while (!pq.empty()) {
// cout << pq.top() << " ";
// pq.pop();
// } cout << endl;
while (k&&!pq.empty()) {
ans-= pq.top();
pq.pop();
k--;
// cout << ans << " ";
}
cout << ans << 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... |