#include <bits/stdc++.h>
using namespace std;
using ayo = int;
using llll = long long;
ayo main(){
llll N, K;
cin >> N >> K;
vector <llll> tamu(N);
for(int i = 0; i < N; i++){
cin >> tamu[i];
}
if(K >= N){
cout << N;
return 0;
}
vector<llll> yaps;
for(int i = 0; i < N; i++){
yaps.reserve(N - 1);
}
for(int i = 0; i < N - 1; i++){
llll awasadasule = tamu[i + 1] - tamu[i] - 1;
yaps.push_back(awasadasule);
}
sort(yaps.begin(), yaps.end());
llll gabungkanOK = N - K; // menggabungkan
llll neraka = 0; // tambahan || ekstra
for(int i = 0; i < gabungkanOK; i++){
neraka += yaps[i];
}
llll jawabanpleasewoi = N + neraka;
cout << jawabanpleasewoi;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |