#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll n,k;
cin >> n >> k;
ll a[n+1];
a[0]=0;
for(ll i = 0;i < n;i++)
{
cin >> a[i];
}
sort(a,a+n+1);
ll ans=a[n-1]-a[0]+1;
vector<ll> v;
for(ll i = 1;i < n;i++)
{
v.push_back(a[i]-a[i-1]-1);
}
sort(v.rbegin(),v.rend());
k--;
for(ll i = 0;i < k;i++)
{
ans-=v[i];
}
cout << ans;
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 |
296 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 |
296 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 |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
308 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
312 KB |
Output is correct |
15 |
Correct |
2 ms |
312 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 |
296 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 |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
308 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
312 KB |
Output is correct |
15 |
Correct |
2 ms |
312 KB |
Output is correct |
16 |
Correct |
49 ms |
3140 KB |
Output is correct |
17 |
Correct |
55 ms |
3080 KB |
Output is correct |
18 |
Correct |
50 ms |
3168 KB |
Output is correct |
19 |
Correct |
46 ms |
3088 KB |
Output is correct |
20 |
Correct |
51 ms |
3140 KB |
Output is correct |
21 |
Correct |
47 ms |
3096 KB |
Output is correct |
22 |
Correct |
63 ms |
3092 KB |
Output is correct |
23 |
Correct |
49 ms |
3164 KB |
Output is correct |
24 |
Correct |
45 ms |
3084 KB |
Output is correct |