#include <bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define ld long double
#define INFF 300000
#define INF (LLONG_MAX - 100)
#define mp make_pair
#define DEBUG(x) cout << "DEBUG: " << x << endl;
#define drugs ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
typedef pair<int, int> pi;
typedef pair<int, pi> ipi;
typedef pair<pi, int> pii;
signed main(){
drugs;
int n, k;
cin >> n >> k;
int ans = n;
vector<int> arr(n);
vector<int> diff;
for(int i = 0; i < n; i++){
cin >> arr[i];
if(i != 0) diff.push_back(arr[i] - arr[i-1]);
}
sort(diff.begin(), diff.end());
for(int i = 0; i < n-k; i++){
ans += diff[i] - 1;
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |