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>
int main(){
int n,k;
std::cin>>n>>k;
std::vector<int> t(n), diff(n-1);
for(int i{}; i < n; ++i)
std::cin>>t[i];
std::sort(t.begin(), t.end());
for(int i{}; i < n-1; ++i)
diff[i]=t[i+1]-t[i]-1;
std::sort(diff.begin(), diff.end());
long long ans{n};
for(int i{}; i < n-k; ++i)
ans+=diff[i];
std::cout << ans << "\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... |