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;
#define maxn 100010
int n, k;
int nums[maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int ans = 0;
vector<int> diffs;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> nums[i];
if (i) ans += nums[i]-nums[i-1];
if (i) diffs.push_back(nums[i]-nums[i-1]-1);
}
ans++; //need to be one past the end
sort(diffs.begin(), diffs.end());
reverse(diffs.begin(), diffs.end());
for (int i = 0; i < k-1; i++) {
ans -= diffs[i];
}
cout << ans << 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... |