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 MAXN = 1e5 + 5;
int arr[MAXN];
vector<int> diff;
int main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> arr[i], diff.push_back(arr[i] - (arr[i - 1] + 1));
diff.erase(diff.begin());
sort(rbegin(diff), rend(diff));
--k;
int ans = arr[n] + 1 - arr[1];
for (int i = 0; i < k; i++) ans -= diff[i];
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |