#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#ifdef lisie_bimbi
#else
#define endl '\n'
#endif
typedef long long ll;
const ll inf = 1'000'000'000'000'000'000;
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,bmi2,fma,popcnt")
//#define int long long
void solve(){
int n, k;
cin >> n >> k;
vector<int> t(n);
for(int i = 0; i < n; i++){
cin >> t[i];
}
k--;
vector<int> z(n - 1);
for(int i = 0; i < n - 1; i++){
z[i] = t[i + 1] - t[i] - 1;
}
std::sort(z.rbegin(), z.rend());
int ans = t.back() + 1 - t[0];
for(int i = 0; i < k; i++){
ans -= z[i];
}
cout << ans << endl;
}
signed main(){
#ifdef lisie_bimbi
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
cin.tie(nullptr)->sync_with_stdio(false);
#endif
cout << setprecision(5) << fixed;
int _ = 1;
//cin >> t;
while(_--){
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
16 ms |
2136 KB |
Output is correct |
17 |
Correct |
14 ms |
2140 KB |
Output is correct |
18 |
Correct |
14 ms |
2140 KB |
Output is correct |
19 |
Correct |
14 ms |
2140 KB |
Output is correct |
20 |
Correct |
22 ms |
2140 KB |
Output is correct |
21 |
Correct |
14 ms |
1992 KB |
Output is correct |
22 |
Correct |
14 ms |
2140 KB |
Output is correct |
23 |
Correct |
15 ms |
1992 KB |
Output is correct |
24 |
Correct |
16 ms |
2140 KB |
Output is correct |