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