# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
886435 | artixkrishna | Stove (JOI18_stove) | C++14 | 0 ms | 0 KiB |
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;
using ll= long long;
int main(){
int n, k, a[1e5+5];
vector<int> res;
for(int i=0; i<=n; i++){
cin>>a[i];
if(i>1) res.push_back(a[i]-a[i-1]);
}
sort(res.begin(), res.end());
int ans =n;
for(int i=0; i<n-k; i++){
ans+=res[i]-1;
}
cout<<ans;
}