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 main() {
int n, k;
cin >> n >> k;
int arr[n];
for (int i=0; i<n; i++) {
cin >> arr[i];
}
sort(arr, arr+n);
int sm = arr[n-1] + 1 - arr[0];
k--;
int df[n-1];
for (int i=0; i<n-1; i++) {
df[i] = arr[i+1] - arr[i] - 1;
}
sort(df, df+n-1, greater<int>());
for (int i=0; i<k; i++) {
sm -= df[i];
}
cout << sm << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |