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 endl "\n"
#define int long long
#define fir first
#define sec second
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, k;
cin >> n >> k;
vector<int> t(n);
for (auto &x : t) {
cin >> x;
}
int res = t.back() - t[0] + 1;
vector<int> nov;
for (int i = 0; i < n - 1; i++) {
nov.push_back(t[i + 1] - t[i] - 1);
}
sort(nov.begin(), nov.end());
reverse(nov.begin(), nov.end());
for (int i = 0; i < k - 1; i++) {
res -= nov[i];
}
cout << res << 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... |