#include<bits/stdc++.h>
#define pb push_back
#define snd second
#define fst first
#define forn(i,n) for(int i=0;i<n;++i)
#define forsn(i,UwU,n) for(int i=UwU; i<n; ++i)
#define SIZE(c) int((c).size())
#define all(x) x.begin(), x.end()
#define imp(x) {for(auto __:x)cout<<__<<" "; cout<<endl;}
#define DBG(x) cerr << #x << " = " << (x) << endl
#define RAYA cerr << "===============================" << endl
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
inline void FIO() {ios_base::sync_with_stdio(false); cin.tie(NULL);}
int main(){FIO;
int n,k;cin>>n>>k;
vi a(n), diff(n);
forn(i,n)cin>>a[i];
forsn(i,1,n){
diff.pb(a[i]-a[i-1]);
}
sort(all(diff));
reverse(all(diff));
ll res=0;
forn(i,k-1){
res+=diff[i];
}
cout<<a[n-1]-a[0]-res+k<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |