#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
vector<int> v(n+2);
vector<ll> pref(n+2), suf(n+2);
for(int i=1; i<=n; i++) cin >> v[i];
for(int i=2; i<=n; i++) pref[i] = max(0, v[i-1]-v[i]+1) + pref[i-1];
for(int i=n-1; i>=1; i--) suf[i] = max(0, v[i+1]-v[i]+1) + suf[i+1];
ll ans = 1e18;
for(int i=1; i<=n; i++) ans = min(ans, max(pref[i], suf[i]));
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
448 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
448 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
444 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
56 ms |
6260 KB |
Output is correct |
27 |
Correct |
57 ms |
6272 KB |
Output is correct |
28 |
Correct |
57 ms |
6248 KB |
Output is correct |
29 |
Correct |
57 ms |
6256 KB |
Output is correct |
30 |
Correct |
46 ms |
5460 KB |
Output is correct |
31 |
Correct |
57 ms |
6228 KB |
Output is correct |
32 |
Correct |
57 ms |
6224 KB |
Output is correct |
33 |
Correct |
60 ms |
6260 KB |
Output is correct |
34 |
Correct |
58 ms |
6228 KB |
Output is correct |
35 |
Correct |
42 ms |
5480 KB |
Output is correct |
36 |
Correct |
49 ms |
5860 KB |
Output is correct |
37 |
Correct |
44 ms |
5480 KB |
Output is correct |
38 |
Correct |
57 ms |
6132 KB |
Output is correct |
39 |
Correct |
58 ms |
6244 KB |
Output is correct |
40 |
Correct |
57 ms |
6228 KB |
Output is correct |
41 |
Correct |
57 ms |
6224 KB |
Output is correct |
42 |
Correct |
53 ms |
5968 KB |
Output is correct |
43 |
Correct |
60 ms |
6128 KB |
Output is correct |
44 |
Correct |
56 ms |
6132 KB |
Output is correct |
45 |
Correct |
57 ms |
6264 KB |
Output is correct |
46 |
Correct |
58 ms |
6128 KB |
Output is correct |
47 |
Correct |
57 ms |
6260 KB |
Output is correct |
48 |
Correct |
57 ms |
6116 KB |
Output is correct |