#include "bits/stdc++.h"
using namespace std;
int main(){
int n, k;
cin >> n >> k;
vector<int> v(n);
for(int &i : v)
cin >> i;
if(k == 1){
cout << v.back() + 1 - v.front() << "\n";
return 0;
}
// int div = ceil(n/2);
// biz aralaryny yakynlasdyrjak bolyas
int ans = v.back() + 1 - v.front();
vector<int> tap;
for(int i = 0; i < n - 1; ++i){
int diff = abs(v[i + 1] - v[i]);
tap.push_back(diff);
}
k--;
sort(tap.begin(), tap.end(), greater<int> ());
for(int i = 1; i <= k; ++i)
ans -= tap[i - 1];
ans += k;
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 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 |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
448 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 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 |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
448 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
34 ms |
2340 KB |
Output is correct |
17 |
Correct |
34 ms |
2216 KB |
Output is correct |
18 |
Correct |
37 ms |
2356 KB |
Output is correct |
19 |
Correct |
34 ms |
2344 KB |
Output is correct |
20 |
Correct |
34 ms |
2264 KB |
Output is correct |
21 |
Correct |
34 ms |
2344 KB |
Output is correct |
22 |
Correct |
43 ms |
2256 KB |
Output is correct |
23 |
Correct |
34 ms |
2424 KB |
Output is correct |
24 |
Correct |
39 ms |
2252 KB |
Output is correct |