#include<bits/stdc++.h>
using namespace std;
int a[(int) 1e5 + 5];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i ++) {
cin >> a[i];
}
sort(a, a + n);
set <pair <int, int>> pri;
for (int i = 1; i < n; i ++) {
pri.insert(make_pair(a[i] - a[i - 1], a[i - 1] + 1));
}
set <int> ep;
while ((int) pri.size() > n - k) {
ep.insert(pri.rbegin()->second);
pri.erase(--pri.end());
}
ep.insert(a[n - 1] + 1);
int r = 0;
for (int i = 0; i < n; i ++) {
r += (*ep.begin()) - a[i];
while (a[i] < *ep.begin() && i < n) {
i ++;
}
ep.erase(ep.begin());
i --;
}
cout << r << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
37 ms |
6484 KB |
Output is correct |
17 |
Correct |
36 ms |
6484 KB |
Output is correct |
18 |
Correct |
34 ms |
6492 KB |
Output is correct |
19 |
Correct |
35 ms |
6404 KB |
Output is correct |
20 |
Correct |
46 ms |
6484 KB |
Output is correct |
21 |
Correct |
53 ms |
6484 KB |
Output is correct |
22 |
Correct |
56 ms |
6432 KB |
Output is correct |
23 |
Correct |
54 ms |
6492 KB |
Output is correct |
24 |
Correct |
56 ms |
6480 KB |
Output is correct |