#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> veci;
typedef vector<ll> vecll;
#define fi first
#define se second
#define vec vector
#define pq priority_queue
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int n, k;
cin >> n >> k;
k = n-k;
int a[n], diff[n-1], i;
for (i=0; i<n; i++) {
cin >> a[i];
}
for (i=0; i<n-1; i++) {
diff[i] = a[i+1]-a[i];
}
sort(diff, diff+n-1);
int ans=n;
for (i=0; i<k; i++) {
ans += diff[i]-1;
}
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... |