#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int mxn = 2e5+5;
ll arr[mxn];
int main()
{
int n, k;
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> arr[i];
sort(arr+1, arr+n+1);
vector<ll>v;
ll sum = 0;
for(int i = 2; i <= n; i++) {
ll d = arr[i]-arr[i-1]-1;
v.push_back(arr[i]-arr[i-1]-1);
sum+=d;
}
sort(v.rbegin(), v.rend());
/*
for(auto it : v) {
cout << it << ' ';
}
cout << '\n';
*/
int x = min((int)v.size(), k-1);
for(int i = 0; i < x; i++) {
sum-=v[i];
}
sum+=n;
cout << sum << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
3 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
3 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
54 ms |
2276 KB |
Output is correct |
17 |
Correct |
52 ms |
2276 KB |
Output is correct |
18 |
Correct |
53 ms |
2404 KB |
Output is correct |
19 |
Correct |
53 ms |
2276 KB |
Output is correct |
20 |
Correct |
55 ms |
2300 KB |
Output is correct |
21 |
Correct |
52 ms |
2276 KB |
Output is correct |
22 |
Correct |
51 ms |
2276 KB |
Output is correct |
23 |
Correct |
54 ms |
2276 KB |
Output is correct |
24 |
Correct |
54 ms |
2276 KB |
Output is correct |