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;
using ll = long long;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n,k,m;
cin >> n >> k;
vector<int>ciag,c2;
for(int i=0;i<n;++i){
cin >> m;
ciag.push_back(m);
}
sort(ciag.begin(),ciag.end());
int suma=0;
for(int i=0;i<n-1;++i){
c2.push_back(ciag[i+1]-ciag[i]);
suma+=ciag[i+1]-ciag[i];
}
sort(c2.begin(),c2.end());
/*for(int i=0;i<c2.size();++i){
cout << c2[i] << ' ';
}
cout << suma << endl; */
for(int i=n-2;i>n-1-k;--i){
suma-=c2[i]-1;
}
cout << suma+1;
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... |