Codeforces Round #318 (Div. 2) D Bear and Blocks

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.