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;
constexpr int nax = 1e5;
int n, k, tab[nax];
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> k;
for (int i = 0; i < n; ++i)
cin >> tab[i];
sort(tab, tab + n);
--k;
vector< int > ilo;
for (int i = 0; i < n - 1; ++i)
ilo.push_back(tab[i + 1] - tab[i] - 1);
sort(begin(ilo), end(ilo));
reverse(begin(ilo), end(ilo));
k = min(k, (int)ilo.size());
//cerr << tab[n - 1] + 1 << ' ' << tab[0] << ' ' << accumulate(ilo.end() - k, ilo.end(), 0) << '\n';
cout << tab[n - 1] + 1 - tab[0] - accumulate(ilo.begin(), ilo.begin() + k, 0) << '\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... |