#include <iostream>
#include <algorithm>
typedef long long ll;
using namespace std;
int mal(ll a, ll b){
return a > b;
}
int main(){
ll n;
ll k;
ll suma = 0;
cin >> n >> k;
ll tab[n];
for(ll i = 0; i < n; i++){
cin >> tab[i];
}
sort(tab, tab+n);
ll roz[n-1];
for(ll i = 0; i < n-1; i++){
roz[i] = tab[i+1] - tab[i]-1;
}
suma = tab[n-1] - tab[0]+1;
sort(roz, roz + n-1, mal);
for(ll i = 0; i < min(k-1, n-1); i++){
suma -= roz[i];
}
cout << suma << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
3 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
3 ms |
336 KB |
Output is correct |
14 |
Correct |
3 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
3 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
3 ms |
336 KB |
Output is correct |
14 |
Correct |
3 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
336 KB |
Output is correct |
16 |
Correct |
44 ms |
2632 KB |
Output is correct |
17 |
Correct |
42 ms |
2376 KB |
Output is correct |
18 |
Correct |
39 ms |
2632 KB |
Output is correct |
19 |
Correct |
36 ms |
1872 KB |
Output is correct |
20 |
Correct |
37 ms |
2640 KB |
Output is correct |
21 |
Correct |
40 ms |
1972 KB |
Output is correct |
22 |
Correct |
41 ms |
1968 KB |
Output is correct |
23 |
Correct |
39 ms |
2312 KB |
Output is correct |
24 |
Correct |
37 ms |
1984 KB |
Output is correct |