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
int32_t main() {
int n, k; cin >> n >> k;
vector<int> t(n);
for (int i = 0; i < n; i++) {
cin >> t[i];
}
int res = t[n - 1] - t[0] + 1;
multiset<int> d;
for (int i = 1; i < n; i++) {
d.insert(t[i] - t[i - 1] - 1);
}
int i = 0;
auto j = d.end();
while (i < k - 1) {
res -= *(--j);
i += 1;
}
cout << res << '\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... |