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;
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int> ii;
const int N = 1e5;
int n, k;
int t[N+2];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> t[i];
sort(t+1,t+n+1);
int ans = t[n]+1-t[1];
priority_queue<int> pq;
for (int i = 2; i <= n; i++) pq.push(t[i]-t[i-1]-1);
for (int i = 1; i <= k-1 && !pq.empty(); i++) {
ans -= pq.top();
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... |