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;
vector<int> a(n+1, 0);
vector<pair<int,int>> b(n+1, {0,0});
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
for (int i = 1; i <= n; i++) {
b[i].first = abs(a[i-1]-a[i])-1;
b[i].second = i;
} sort(b.rbegin(), b.rend());
int sum = a[n]-a[1]+1;
for (int i = 0; i < k-1; i++) {
sum -= b[i].first;
} cout << sum;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |