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;
int n, k;
vector<int> have;
int a[101010];
int main()
{
cin >> n >> k;
for (int i = 1; i <= n; i++)cin >> a[i];
for (int i = 1; i < n; i++)
have.push_back(a[i + 1] - a[i] - 1);
sort(have.begin(), have.end(), greater<int>());
int ans = a[n] - a[1] + 1;
k--;
for (auto i : have) {
if (--k < 0)break;
ans -= i;
}
cout << ans;
}
/**
10 5
1
2
5
6
8
11
13
15
16
20
3 2
1 3 6
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |