#include <bits/stdc++.h>
using namespace std;
const int mxN=1e5;
int n, k, t1, t2, ans, d[mxN-1];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for(int i=0; i<n; ++i) {
cin >> t2;
if(i)
d[i-1]=t2-t1-1;
t1=t2;
}
ans=n;
sort(d, d+n-1);
for(int i=0; i<n-k; ++i)
ans+=d[i];
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
360 KB |
Output is correct |
3 |
Correct |
2 ms |
600 KB |
Output is correct |
4 |
Correct |
2 ms |
600 KB |
Output is correct |
5 |
Correct |
2 ms |
600 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
632 KB |
Output is correct |
8 |
Correct |
2 ms |
652 KB |
Output is correct |
9 |
Correct |
2 ms |
656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
360 KB |
Output is correct |
3 |
Correct |
2 ms |
600 KB |
Output is correct |
4 |
Correct |
2 ms |
600 KB |
Output is correct |
5 |
Correct |
2 ms |
600 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
632 KB |
Output is correct |
8 |
Correct |
2 ms |
652 KB |
Output is correct |
9 |
Correct |
2 ms |
656 KB |
Output is correct |
10 |
Correct |
3 ms |
660 KB |
Output is correct |
11 |
Correct |
3 ms |
820 KB |
Output is correct |
12 |
Correct |
4 ms |
828 KB |
Output is correct |
13 |
Correct |
3 ms |
880 KB |
Output is correct |
14 |
Correct |
3 ms |
928 KB |
Output is correct |
15 |
Correct |
3 ms |
1032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
360 KB |
Output is correct |
3 |
Correct |
2 ms |
600 KB |
Output is correct |
4 |
Correct |
2 ms |
600 KB |
Output is correct |
5 |
Correct |
2 ms |
600 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
632 KB |
Output is correct |
8 |
Correct |
2 ms |
652 KB |
Output is correct |
9 |
Correct |
2 ms |
656 KB |
Output is correct |
10 |
Correct |
3 ms |
660 KB |
Output is correct |
11 |
Correct |
3 ms |
820 KB |
Output is correct |
12 |
Correct |
4 ms |
828 KB |
Output is correct |
13 |
Correct |
3 ms |
880 KB |
Output is correct |
14 |
Correct |
3 ms |
928 KB |
Output is correct |
15 |
Correct |
3 ms |
1032 KB |
Output is correct |
16 |
Correct |
25 ms |
2272 KB |
Output is correct |
17 |
Correct |
24 ms |
3236 KB |
Output is correct |
18 |
Correct |
25 ms |
4200 KB |
Output is correct |
19 |
Correct |
25 ms |
5312 KB |
Output is correct |
20 |
Correct |
23 ms |
6116 KB |
Output is correct |
21 |
Correct |
24 ms |
7124 KB |
Output is correct |
22 |
Correct |
26 ms |
8204 KB |
Output is correct |
23 |
Correct |
35 ms |
9156 KB |
Output is correct |
24 |
Correct |
34 ms |
10076 KB |
Output is correct |