#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
int N; cin >> N;
vector<ll> arr(N);
for(int i = 0;i<N;++i) cin >> arr[i];
vector<ll> f(N,0),g(N,0); //f : for increasing numbers before i; g : for decreasing numbers after i (that are bigger than arr[i])
for(int i = 1;i<N;++i){
f[i] = f[i-1]+max(arr[i-1]-arr[i]+1,0ll);
}
for(int i = N-2;i>=0;--i){
g[i] = g[i+1]+max(arr[i+1]-arr[i]+1,0ll);
}
ll ans = 1e18;
for(int i = 0;i<N;++i){
//cout << f[i] << " " << g[i] << "\n";
ans = min(ans,max(f[i],g[i]));
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
304 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
316 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
304 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
316 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
63 ms |
6836 KB |
Output is correct |
27 |
Correct |
58 ms |
6836 KB |
Output is correct |
28 |
Correct |
59 ms |
6836 KB |
Output is correct |
29 |
Correct |
61 ms |
6840 KB |
Output is correct |
30 |
Correct |
47 ms |
6204 KB |
Output is correct |
31 |
Correct |
59 ms |
6860 KB |
Output is correct |
32 |
Correct |
71 ms |
6836 KB |
Output is correct |
33 |
Correct |
58 ms |
6892 KB |
Output is correct |
34 |
Correct |
58 ms |
6840 KB |
Output is correct |
35 |
Correct |
42 ms |
6084 KB |
Output is correct |
36 |
Correct |
43 ms |
6184 KB |
Output is correct |
37 |
Correct |
43 ms |
6192 KB |
Output is correct |
38 |
Correct |
58 ms |
6832 KB |
Output is correct |
39 |
Correct |
58 ms |
6860 KB |
Output is correct |
40 |
Correct |
59 ms |
6836 KB |
Output is correct |
41 |
Correct |
58 ms |
6844 KB |
Output is correct |
42 |
Correct |
54 ms |
6704 KB |
Output is correct |
43 |
Correct |
59 ms |
6836 KB |
Output is correct |
44 |
Correct |
57 ms |
6908 KB |
Output is correct |
45 |
Correct |
58 ms |
6836 KB |
Output is correct |
46 |
Correct |
69 ms |
6852 KB |
Output is correct |
47 |
Correct |
60 ms |
6840 KB |
Output is correct |
48 |
Correct |
75 ms |
6848 KB |
Output is correct |