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>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define pii pair<int,int>
#define piii pair<int,pii>
#define sp " "
#define nl "\n"
#define all(x) x.begin(),x.end()
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long
using namespace std;
const int N = 1e5+5;
const int INF = 1e9+5;
const int mod = 1e9+7;
int n,k,a[N],ans;
signed main(){
fastio()
cin >> n >> k;
vector<int> v;
for(int i=1;i<=n;i++){
cin >> a[i];
if(i>1){
ans+=a[i]-a[i-1];
v.pb(a[i]-a[i-1]);
}
}
sort(v.rbegin(),v.rend());
for(int i=0;i<k-1;i++){
ans-=v[i];
}
cout << ans+k << nl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |