#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
int main() {
int n, k;
cin >> n >> k;
int a[n];
k--;
for(int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> v;
for(int i = 1; i < n; i++) {
v.push_back(a[i] - a[i - 1] - 1);
}
// for(auto x:v) cout << x << ' ';
// return 0;
sort(v.begin(), v.end());
int s = 0;
for(int i = 0; i < n - k - 1 ; i++) {
s += v[i];
}
cout << n + s << '\n';
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... |