#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
int n, k;
int arr[100000];
int dis[100000];
void solve(){
cin>> n>> k;
for(int i=0; i<n; i++){
cin>> arr[i];
}
for(int i=0; i<n-1; i++){
dis[i]=arr[i+1]-(arr[i]+1);
}
sort(dis, dis+n-1);
int ans=0;
for(int i=0; i<n-k; i++)
ans+=dis[i];
cout<< ans+n;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int t=1;
//cin>> t;
while(t--)
solve();
return 0;
}
/*
Se que es difícil, todo lo bueno es así...
pero cada día se hará un poco más fácil, pero tienes que hacerlo cada día,
esa es la parte difícil. Lamentablemente crecer duele.
Pero única manera de pasar esa barrera es esforzandote, tendrás que hacer
sacrificios; pero no sirve de nada hacer sacrificios si no tienes disciplina.
Si te caes 7 veces, levántate 8.
La DISCIPLINA es el puente entre tus metas y tus logros.
El único que define tus límites eres tú mismo, así que si quieres
lograr eso aquello que anelas, tienes que esforzarte y dar lo mejor de ti
ya que si das tu máximo cada uno de los días, el éxito vendra solo.
Ten el corage de llevarte al límite, sobrepasar ese límite y realizar lo
que alguna ves creiste imposible.
Sueña en grande y haz que suceda...
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
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 |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 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 |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
15 ms |
2136 KB |
Output is correct |
17 |
Correct |
15 ms |
1992 KB |
Output is correct |
18 |
Correct |
14 ms |
2112 KB |
Output is correct |
19 |
Correct |
15 ms |
2140 KB |
Output is correct |
20 |
Correct |
15 ms |
2136 KB |
Output is correct |
21 |
Correct |
15 ms |
2140 KB |
Output is correct |
22 |
Correct |
14 ms |
2140 KB |
Output is correct |
23 |
Correct |
18 ms |
2184 KB |
Output is correct |
24 |
Correct |
15 ms |
2064 KB |
Output is correct |