#include <bits/stdc++.h>
using namespace std;
#define PB push_back
typedef vector<int> vec;
int main(){
int n,k;
cin>>n>>k;
vec dn(n);
for(int i=0;i<n;i++){
cin>>dn[i];
}
vec dm(n-1);
for(int i=0;i<n-1;i++){
dm[i]=dn[i+1]-dn[i]-1;
}
sort(dm.rbegin(),dm.rend());
int s=dn[n-1]-dn[0]+1;
for(int i=0;i<k-1;i++){
s-=dm[i];
}
cout<<s<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
312 KB |
Output is correct |
11 |
Correct |
2 ms |
312 KB |
Output is correct |
12 |
Correct |
2 ms |
316 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
312 KB |
Output is correct |
11 |
Correct |
2 ms |
312 KB |
Output is correct |
12 |
Correct |
2 ms |
316 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
46 ms |
1952 KB |
Output is correct |
17 |
Correct |
44 ms |
2024 KB |
Output is correct |
18 |
Correct |
45 ms |
1944 KB |
Output is correct |
19 |
Correct |
44 ms |
1996 KB |
Output is correct |
20 |
Correct |
45 ms |
1944 KB |
Output is correct |
21 |
Correct |
44 ms |
1956 KB |
Output is correct |
22 |
Correct |
45 ms |
2028 KB |
Output is correct |
23 |
Correct |
45 ms |
1956 KB |
Output is correct |
24 |
Correct |
46 ms |
2068 KB |
Output is correct |