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;
#define int long long
signed main() {
//your code goes here
int n, k;
cin >> n >> k;
vector <int> arr = {};
for(int i = 0; i < n; i++) {
int num;
cin >> num;
arr.push_back(num);
}
int sum = 1;
k--;
vector <int> arr2 = {};
for(int i = 0; i < n-1; i++) {
arr2.push_back(arr[i+1]-arr[i]);
sum += arr[i+1]-arr[i];
}
sort(arr2.begin(), arr2.end(), greater<int>());
for(int i = 0; i < k; i++) {
sum -= arr2[i];
}
sum += k;
cout << sum << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |