This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int N, K;
int arr[100005];
int dif[100005];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> K;
for(int i = 1; i<=N; i++){
cin >> arr[i];
dif[i-1] = arr[i] - arr[i-1];
}
sort(dif+1, dif+N);
K = N - K;
int ans = 0;
for(int i = 1; i<=K; i++){
ans += dif[i];
}
cout << ans+ N - K << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |