This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// I stand with PALESTINE
//#pragma GCC optimize("Ofast,O3")
//#pragma GCC target("avx,avx2")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll inf = 1e18;
void solve() {
int n, k;
cin >> n >> k;
vector<int> t(n), d;
for (int &x: t) cin >> x;
for (int i = 1; i < n; i++) d.emplace_back(t[i] - t[i - 1]);
int ans = t.back() + 1 - t[0];
sort(d.rbegin(), d.rend());
k--;
for (int i = 0; i < k; i++) ans -= d[i] - 1;
cout << ans;
}
int main() {
cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int q = 1;
// cin >> q;
while (q--) {
solve();
cout << '\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... |