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;
const int DIM = 100005;
int lst[DIM], arr[DIM];
int main(void) {
#ifdef HOME
freopen("stove.in", "r", stdin);
freopen("stove.out", "w", stdout);
#endif
int n, k; cin >> n >> k; --k;
for (int i = 1; i <= n; ++i) {
cin >> arr[i];
if (i > 1) {
lst[i - 1] = arr[i] - arr[i - 1] - 1; } }
sort(lst + 1, lst + n, greater<int>());
int ans = arr[n] - arr[1] + 1;
for (int i = 1; i <= k; ++i) {
ans -= lst[i]; }
cout << ans;
return 0; }
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |