#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n, k;
cin>>n>>k;
ll a[n];
for(ll i=0;i<n;i++) cin>>a[i];
ll b[n-1];
for(ll i=0;i<n-1;i++) b[i]=a[i+1]-a[i]-1;
sort(b,b+n-1);
ll res = n;
for(ll i=0;i<n-k;i++) res+=b[i];
cout<<res<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
300 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
300 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 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 |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
316 KB |
Output is correct |
12 |
Correct |
2 ms |
312 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
308 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 |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
300 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 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 |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
316 KB |
Output is correct |
12 |
Correct |
2 ms |
312 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
308 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
46 ms |
2700 KB |
Output is correct |
17 |
Correct |
43 ms |
2712 KB |
Output is correct |
18 |
Correct |
44 ms |
2796 KB |
Output is correct |
19 |
Correct |
46 ms |
2764 KB |
Output is correct |
20 |
Correct |
43 ms |
2784 KB |
Output is correct |
21 |
Correct |
43 ms |
2796 KB |
Output is correct |
22 |
Correct |
62 ms |
2704 KB |
Output is correct |
23 |
Correct |
53 ms |
2708 KB |
Output is correct |
24 |
Correct |
42 ms |
2716 KB |
Output is correct |