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>
typedef long long ll;
int main() {
std::ios::sync_with_stdio(0); std::cin.tie(0);
int n, k; std::cin >> n >> k;
std::vector <int> a(n);
for (int& x : a) std::cin >> x;
std::sort(a.begin(), a.end());
ll ans = a.back() - a.front();
std::vector <ll> in(n - 1);
for (int i = 0; i < n - 1; i++) in[i] = a[i + 1] - a[i] - 1;
std::sort(in.begin(), in.end());
while (--k) ans -= in.back(), in.pop_back();
std::cout << ans + 1 << "\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... |