#include<bits/stdc++.h>
using namespace std;
long long n , a [200005] , suma , sumb , ans = 1e18 , dif [200005] , rdif [200005];
int main ()
{
cin >> n;
for ( int i = 1 ; i <= n ; i ++ )
{
cin >> a [i];
if ( i != 1 ) dif [i] = max ( 0ll , a [ i - 1 ] - a [i] + 1 );
dif [i] += dif [ i - 1 ];
}
for ( int i = n ; i >= 1 ; i -- )
{
if ( i != n ) rdif [i] = max ( 0ll , a [ i + 1 ] - a [i] + 1 );
rdif [i] += rdif [ i + 1 ];
}
for ( int i = 1 ; i <= n ; i ++ ) ans = min ( ans , max ( dif [i] , rdif [i] ) );
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
360 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
312 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 |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
1 ms |
320 KB |
Output is correct |
21 |
Correct |
1 ms |
356 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
360 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
312 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 |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
1 ms |
320 KB |
Output is correct |
21 |
Correct |
1 ms |
356 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
74 ms |
6880 KB |
Output is correct |
27 |
Correct |
75 ms |
6860 KB |
Output is correct |
28 |
Correct |
79 ms |
6832 KB |
Output is correct |
29 |
Correct |
78 ms |
6904 KB |
Output is correct |
30 |
Correct |
55 ms |
6152 KB |
Output is correct |
31 |
Correct |
77 ms |
6896 KB |
Output is correct |
32 |
Correct |
75 ms |
6988 KB |
Output is correct |
33 |
Correct |
73 ms |
6860 KB |
Output is correct |
34 |
Correct |
74 ms |
6944 KB |
Output is correct |
35 |
Correct |
52 ms |
6092 KB |
Output is correct |
36 |
Correct |
56 ms |
6184 KB |
Output is correct |
37 |
Correct |
54 ms |
6188 KB |
Output is correct |
38 |
Correct |
90 ms |
6844 KB |
Output is correct |
39 |
Correct |
77 ms |
6896 KB |
Output is correct |
40 |
Correct |
75 ms |
6868 KB |
Output is correct |
41 |
Correct |
72 ms |
6876 KB |
Output is correct |
42 |
Correct |
73 ms |
6636 KB |
Output is correct |
43 |
Correct |
75 ms |
6844 KB |
Output is correct |
44 |
Correct |
74 ms |
6796 KB |
Output is correct |
45 |
Correct |
75 ms |
6908 KB |
Output is correct |
46 |
Correct |
74 ms |
6888 KB |
Output is correct |
47 |
Correct |
94 ms |
6916 KB |
Output is correct |
48 |
Correct |
80 ms |
6936 KB |
Output is correct |