#include<bits/stdc++.h>
#define endl "\n"
#define int long long int
#define pb push_back
#define mp make_pair
#define Bound 2e5 + 1
#define mid (l+r+1)/2
using namespace std;
void solve() {
int n,k;
cin >> n >> k;
int* arr = new int[n];
int* fuel = new int[n-1];
for(int i = 0; i < n; i++) {
cin >> arr[i];
}
for(int i = 1; i < n; i++) {
fuel[i-1] = arr[i]-arr[i-1];
}
sort(fuel,fuel+n-1);
int usage = 0;
for(int i = n-k-1; i >= 0; i--) usage += fuel[i];
cout << usage+k;
}
int32_t main() {
cin.tie(0); cout.tie(0);
//ios::sync_with_stdio(false);
int t = 1; //cin >> t;
while(t--) solve();
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... |