It is not difficult to find that after an operation, Hi=min (hi-1,hi-1,hi+1), the iteration of this equation gets K operations after Hi=min (hi-j-(k-j), hi-k,hi+j-(K-j)), j = ...
When k = = min (hi-j+j,hi+j+j) when the hi will become 0, because Min has transitivity, then can be left and right to consider, Hi-j+j is hi-j-(i-j) +i, wherein I and j is irrelevant, so just find the front of the smallest hi-i
For similar processing on the right, and then sweep again, the biggest one is the answer.
#include <bits/stdc++.h>using namespacestd;Const intMAXN = 1e5+2;intN;intH[MAXN];intK[MAXN];intMain () {scanf ("%d",&N); for(inti =1; I <= N; i++) scanf ("%d", H +i); intCNT =0; for(inti =1; I <= N; i++) {CNT= Min (cnt,h[i]-i); K[i]= i +CNT; } CNT= n+1; for(inti = n; I >=1; i--) {CNT= Min (cnt,h[i]+i); K[i]= Min (k[i],cnt-i); } intAns =0; for(inti =1; I <= N; i++) {ans=Max (ans,k[i]); } printf ("%d\n", ans); return 0;}
Codeforces Round #318 (Div. 2) D Bear and Blocks