#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int v[maxn];
priority_queue<int, vector<int>, greater<int>> near;
int main(){
int n, k; cin >> n >> k;
for(int i = 0; i < n; i++) cin >> v[i];
sort(v, v+n);
for(int i = 1; i < n; i++) near.push(v[i]+1 - v[i-1]);
int ans = n;
k = n-k;
while(k--) ans += near.top()-2, near.pop();
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
316 KB |
Output is correct |
13 |
Correct |
2 ms |
320 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
316 KB |
Output is correct |
13 |
Correct |
2 ms |
320 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
51 ms |
2192 KB |
Output is correct |
17 |
Correct |
53 ms |
2176 KB |
Output is correct |
18 |
Correct |
54 ms |
2236 KB |
Output is correct |
19 |
Correct |
49 ms |
2248 KB |
Output is correct |
20 |
Correct |
47 ms |
2204 KB |
Output is correct |
21 |
Correct |
46 ms |
2244 KB |
Output is correct |
22 |
Correct |
41 ms |
2244 KB |
Output is correct |
23 |
Correct |
40 ms |
2296 KB |
Output is correct |
24 |
Correct |
44 ms |
2224 KB |
Output is correct |