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;
typedef long long ll;
typedef long double ld;
int niz[100005];
int g[100005];
int main(){
ios_base::sync_with_stdio(false);
cout.precision(10);
cout<<fixed;
int n, k;
cin >> n >> k;
k--;
for(int i=1; i<=n; i++){
cin >> niz[i];
}
for(int i=2; i<=n; i++){
g[i] = niz[i] - niz[i-1] - 1;
}
sort(g+1, g+1+n);
reverse(g+1, g+1+n);
int res = niz[n]+1-niz[1];
for(int i=1; i<=k; i++) res -= g[i];
cout << res;
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... |