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;
typedef long long ll;
typedef long double ld;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, k;
cin >> n >> k;
int lst = -1;
vector <int> dif;
for (int i = 0; i < n; ++i) {
int t;
cin >> t;
if (lst != -1) {
dif.push_back(t - lst);
}
lst = t + 1;
}
int cnt = n;
int ans = n;
sort(dif.begin(), dif.end());
for (auto x : dif) {
if (cnt > k) {
--cnt;
ans += x;
}
}
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... |