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 int long long
using namespace std;
signed main(){
cin.tie(nullptr) -> sync_with_stdio(0);
int n, k;
cin >> n >> k;
priority_queue<int> pq;
vector<int> t(n+5);
for (int i = 1; i <= n; i++){
cin >> t[i];
}
for (int i = 2; i <= n; i++){
pq.push(t[i] - t[i-1] - 1);
}
k--;
int ans = t[n];
while(!pq.empty() && k){
ans -= pq.top();
pq.pop();
k--;
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |