#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxn = 5e5+5;
typedef pair<ll,ll>pii;
ll arr[mxn];
vector<ll>gap;
int main()
{
ll n, k;
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> arr[i];
for(int i = 1; i < n; i++) gap.push_back(arr[i+1]-arr[i]-1);
sort(gap.rbegin(), gap.rend());
ll ans = arr[n]-arr[1]+1;
for(int i = 0; i < k-1; i++) ans-=gap[i];
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
364 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
360 KB |
Output is correct |
8 |
Correct |
5 ms |
372 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
364 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
360 KB |
Output is correct |
8 |
Correct |
5 ms |
372 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
9 ms |
384 KB |
Output is correct |
11 |
Correct |
7 ms |
508 KB |
Output is correct |
12 |
Correct |
7 ms |
384 KB |
Output is correct |
13 |
Correct |
7 ms |
384 KB |
Output is correct |
14 |
Correct |
7 ms |
488 KB |
Output is correct |
15 |
Correct |
8 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
364 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
360 KB |
Output is correct |
8 |
Correct |
5 ms |
372 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
9 ms |
384 KB |
Output is correct |
11 |
Correct |
7 ms |
508 KB |
Output is correct |
12 |
Correct |
7 ms |
384 KB |
Output is correct |
13 |
Correct |
7 ms |
384 KB |
Output is correct |
14 |
Correct |
7 ms |
488 KB |
Output is correct |
15 |
Correct |
8 ms |
512 KB |
Output is correct |
16 |
Correct |
82 ms |
3196 KB |
Output is correct |
17 |
Correct |
81 ms |
3288 KB |
Output is correct |
18 |
Correct |
79 ms |
3184 KB |
Output is correct |
19 |
Correct |
83 ms |
3188 KB |
Output is correct |
20 |
Correct |
78 ms |
3288 KB |
Output is correct |
21 |
Correct |
79 ms |
3208 KB |
Output is correct |
22 |
Correct |
84 ms |
3184 KB |
Output is correct |
23 |
Correct |
77 ms |
3184 KB |
Output is correct |
24 |
Correct |
76 ms |
3236 KB |
Output is correct |