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;
vector<int> difs, v;
int ant, n, k;
int main() {
#ifdef HOME
freopen("joi_stove.in", "r", stdin);
freopen("joi_stove.out", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> k;
v.resize(n);
for (auto &i: v)
cin >> i;
difs.reserve(n - 1);
sort(begin(v), end(v));
for (int i = 1; i < n; ++i)
difs.push_back(v[i] - v[i - 1] - 1);
ant = n;
sort(begin(difs), end(difs));
for (int i = 0; i < n - k; ++i)
ant+= difs[i];
cout << ant << '\n';
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... |