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