#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pll pair<ll, ll>
#define pb push_back
#define bp pop_back
#define ades ios_base::sync_with_stdio(false); cin.tie(NULL);
ll N, M, a[100010], ans;
bool bener[100010];
pair<ll, ll> ada[100010];
int main(){
cin >> N >> M;
for(int i = 1; i<= N; i++){
cin >> a[i];
}
for(int i = 1; i< N; i++){
ada[i].fi = a[i+1]-a[i];
ada[i].se = i;
}
sort(ada+1, ada+N);
if(N <= M){
// for(int i = 1; i< N; i++){
// if(a[i] == a[i+1]){
// ans++;
// }
// else{
// ans++;
// }
// }
cout << N << endl;
return 0;
}
for(int i = 1; i<= N-M; i++){
bener[ada[i].se] = true;
// cout << ada[i].se << endl;
}
for(int i = 1; i<= N; i++){
if(bener[i]){
ans += a[i+1]-a[i];
}
else{
ans++;
}
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
312 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
312 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
324 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
312 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
324 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
320 KB |
Output is correct |
16 |
Correct |
38 ms |
3500 KB |
Output is correct |
17 |
Correct |
36 ms |
3400 KB |
Output is correct |
18 |
Correct |
45 ms |
3396 KB |
Output is correct |
19 |
Correct |
36 ms |
3388 KB |
Output is correct |
20 |
Correct |
37 ms |
3492 KB |
Output is correct |
21 |
Correct |
36 ms |
3500 KB |
Output is correct |
22 |
Correct |
38 ms |
3396 KB |
Output is correct |
23 |
Correct |
36 ms |
3416 KB |
Output is correct |
24 |
Correct |
36 ms |
3340 KB |
Output is correct |