#include "bits/stdc++.h"
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << (#x) << " " << (x) << endl
#define SZ(s) ((int)s.size())
#define pb push_back
#define ff first
#define ss second
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
int main(){
int n, k;
cin >> n >> k;
vi a(n);
for(int &x : a) cin >> x;
vi dif;
for(int i = 1; i < n; i ++){
dif.pb(a[i] - a[i - 1]);
}
sort(all(dif));
int ans = 0;
for(int i = 0; i < n - k; i ++){
ans += dif[i];
}
cout << ans + k;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |