#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pll pair<ll,ll>
#define pqll priority_queue<ll>
#define pqpll priority_queue<pll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>
#define pqpllg priority_queue<pll, vector<pll>, greater<pll>>
#define inf LLONG_MAX
#define vll vector<ll>
#define vqll vector<queue<ll>>
#define qll queue<ll>
#define sll set<ll>
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll n,k;cin>>n>>k;
pqll pq; ll s[n];
for(ll i=0;i<n;i++){
ll a;cin>>a;
s[i]=a;
}
for(ll i=0;i<n-1;i++){
pq.push(s[i+1]-s[i]-1);
}
ll cnt=s[n-1]-s[0]+1;
for(ll i=0;i<n-k;i++){
cnt-=pq.top();
pq.pop();
}
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... |