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;
int main() {
int n, k;
cin >> n >> k;
vector<int> t(n);
for (int i = 0; i < n; i++) {
cin >> t[i];
}
t.push_back(INT_MAX);
priority_queue<int> pq;
for (int i = n; i > 0; i--) {
pq.push(t[i]-t[i-1]-1);
}
int ans = n;
for (int i = 0; i < k; i++) {
pq.pop();
}
while (!pq.empty()) {
ans += pq.top();
pq.pop();
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |