#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
int const MOD = 1e9 + 7, N = 1e5 + 4;
int n, k, a[N];
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> a[i];
int s[N];
int mag = a[n] + 1 - a[1];
//cout << mag << "\n";
for(int i = 1; i < n; i++){
s[i] = a[i + 1] - 1 - a[i];
//cout << i << ":" << s[i] << "\n";
}
s[n] = 1;
sort(s + 1, s + n + 1);
int cuoi = n;
for(int i = 1; i < k; i++){
mag -= s[cuoi];
cuoi--;
}
cout << mag;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |