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 int long long
using namespace std;
signed main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, a, b, k, ans; cin >> n >> k >> a; ans=n;
priority_queue<int, vector<int>, greater<int>> pq;
for(int i=1; i<n; i++) b=a, cin >> a, pq.push(a-b);
while((k++)<n) ans+=pq.top()-1, pq.pop();
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |