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>
using namespace std;
typedef long long ll;
const ll MAXN = 1e5 + 5;
ll n, k;
ll a [MAXN];
priority_queue <ll, vector <ll> , greater <ll> > pq;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k;
ll ans = n;
for(ll i = 1; i <= n; i++){
cin >> a[i];
}
for(ll i = 1; i <= n-1; i++){
pq.push(a[i+1] - (a[i]+1));
}
ll sambung = n - k;
while(sambung--){
ans += pq.top();
pq.pop();
}
cout << ans << 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... |