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;
int n, k, t, ans;
int main(){
cin >> n >> k;
int a[n], in[n-1];
for(int i=0; i<n; i++){
cin >> a[i];
}
ans=a[n-1]-a[0]+1;
for(int i=0; i<n-1; i++){
in[i]=a[i+1]-a[i]-1;
}
sort(in, in+n-1);
for(int i=0; i<k-1; i++){
ans-=in[n-2-i];
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |