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 <iostream>
#include <algorithm>
typedef long long ll;
using namespace std;
int mal(ll a, ll b){
return a > b;
}
int main(){
ll n;
ll k;
ll suma = 0;
cin >> n >> k;
ll tab[n];
for(ll i = 0; i < n; i++){
cin >> tab[i];
}
sort(tab, tab+n);
ll roz[n-1];
for(ll i = 0; i < n-1; i++){
roz[i] = tab[i+1] - tab[i]-1;
}
suma = tab[n-1] - tab[0]+1;
sort(roz, roz + n-1, mal);
for(ll i = 0; i < min(k-1, n-1); i++){
suma -= roz[i];
}
cout << suma << "\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... |