#include <bits/stdc++.h>
using namespace std;
int main (){
ios_base::sync_with_stdio(0);
int n, k;
cin >> n >> k;
vector <int> a(n), dif;
for (int &i : a) cin >> i;
for (int i = 1; i < n; i++)
dif.push_back(a[i] - a[i - 1]);
sort(dif.begin(), dif.end());
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... |