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 <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
int n, k; cin >> n >> k;
vector<int> t(n);
for(auto &x : t) {
cin >> x;
}
priority_queue<int> pq;
for(int i = 1; i < n; ++i)
pq.emplace(t[i] - t[i-1] - 1);
int ans = t[n-1] - t[0] + 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... |