#include <bits/stdc++.h>
using namespace std;
#define N 500005
#define sz size()
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define pt pop_back
ll a[N], b[N], c, l, k, tr, b1, c1, d, t, n, h;
string s, g;
int main() {
ios::sync_with_stdio(false);cin.tie(0);
cin >> n >> k;
c = n - k;
h += n;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++){
if(i + 1 <= n){
l ++;
b[l] = a[i + 1] - a[i] - 1;
}
}
sort(b + 1, b + l + 1);
// for(int i = 1; i <= l; i++)cout << b[i] << ' ';
// return 0;
for(int i = 1; i <= c; i++){
h += b[i];
}
cout << h<< '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
2 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2596 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
2 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2596 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
2 ms |
2400 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
2384 KB |
Output is correct |
13 |
Correct |
2 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
2 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2596 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
2 ms |
2400 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
2384 KB |
Output is correct |
13 |
Correct |
2 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2552 KB |
Output is correct |
16 |
Correct |
16 ms |
7760 KB |
Output is correct |
17 |
Correct |
17 ms |
7760 KB |
Output is correct |
18 |
Correct |
16 ms |
7760 KB |
Output is correct |
19 |
Correct |
16 ms |
7760 KB |
Output is correct |
20 |
Correct |
16 ms |
7772 KB |
Output is correct |
21 |
Correct |
17 ms |
7652 KB |
Output is correct |
22 |
Correct |
16 ms |
7580 KB |
Output is correct |
23 |
Correct |
15 ms |
7760 KB |
Output is correct |
24 |
Correct |
16 ms |
7760 KB |
Output is correct |