This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//*--- ©ZeroCoolCorp --- *//
#include <bits/stdc++.h>
#define endl '\n'
#define debug(v) cerr<<v<<endl;
#define ll long long
#define ld long double
using namespace std;
const int mxn = 2e5 + 5;
const int LOG = 20;
const int mod = 1e9 + 7;
const int inf = 1e9;
void solve(int T){
priority_queue<int,vector<int>,greater<int>>q;
int n,k;
cin>>n>>k;
int a[n];
for(int i = 0;i < n;i++){
cin>>a[i];
if(i > 0)q.push(a[i] - a[i - 1]);
}
ll ans = n;
k = n - k;
while(k > 0){
ans += q.top();
ans--;
q.pop();
k--;
}
cout<<ans<<endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin>>t;
for(int i = 1;i<=t;i++)solve(i);
}
//*--- This is code from the best programer ---*//
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |