#include <bits/stdc++.h>
#define imie(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> T(n);
for(int i = 0; i < n; i++) {
cin >> T[i];
}
vector<int> diff(n, 0);
for(int i = 1; i < n; i++) {
diff[i] = T[i] - T[i - 1] - 1;
}
sort(diff.rbegin(), diff.rend());
ll ans = T[n - 1] + 1 - T[0];
for(int i = 0; i < k - 1; i++) {
ans -= max(0, diff[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... |