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 deb(x) cerr << #x << " = " << x << "\n";
#define deb2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << "\n";
#define deb3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << "\n";
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
typedef long long ll;
void solve() {
int n, k;
cin >> n >> k;
vector<int> ent(n);
for (int i = 0; i < n; ++i) {
cin >> ent[i];
}
priority_queue<int> pq;
sort(all(ent));
for (int i = 0; i < n-1; ++i) {
pq.push(ent[i+1] - ent[i] - 1);
}
int a = 0;
for (int i = 0; i < k-1 && !pq.empty(); ++i) {
a+= pq.top();
pq.pop();
}
cout << (ent[n-1] - ent[0] - a + 1);
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
ll tc = 1;
//cin >> tc;
while(tc--) {
solve();
cout << '\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... |