#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef double dbl;
typedef pair<ll,ll> pii;
const int maxn = 1e5+5;
ll N,K,T[maxn],ans;
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> N >> K;
priority_queue<ll> pq;
for(int i =1; i <= N; i++){
cin >> T[i];
pq.push(T[i]-T[i-1]-1);
}
ans = T[N] - T[1] + 1;
//cout << ans << '\n';
K--;
while(K-- && !pq.empty()){
auto cur = pq.top();
pq.pop();
ans -= cur;
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |