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 <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;
int n, k;
int t[101010];
int res = 0;
vector<int> dif;
int32_t main()
{
cin >> n >> k;
for (int i = 1; i <= n; i++)
cin >> t[i];
for (int i = 2; i <= n; i++) {
dif.push_back(t[i] - t[i - 1]);
}
res = t[n] - t[1] + 1;
sort(dif.begin(), dif.end(), greater<int>());
for (int i = 0; i + 1 < k; i++) {
res -= dif[i];
res++;
}
cout << res;
}
/**
3 2
1
3
6
3 1
1
3
6
10 5
1
2
5
6
8
11
13
15
16
20
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |