codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

573B.md (1664B)


      1 Source: https://codeforces.com/problemset/problem/573/B
      2 
      3 B. Bear and Blocks
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built *n* towers in a row. The *i*-th tower is made of *h**i* identical blocks. For clarification see picture for the first sample.
     22 
     23 Limak will repeat the following operation till everything is destroyed.
     24 
     25 Block is called internal if it has all four neighbors, i.e. it has each side (top, left, down and right) adjacent to other block or to the floor. Otherwise, block is boundary. In one operation Limak destroys all boundary blocks. His paws are very fast and he destroys all those blocks at the same time.
     26 
     27 Limak is ready to start. You task is to count how many operations will it take him to destroy all towers.
     28 
     29 Input
     30 
     31 The first line contains single integer *n* (1 ≤ *n* ≤ 105).
     32 
     33 The second line contains *n* space-separated integers *h*1, *h*2, ..., *h**n* (1 ≤ *h**i* ≤ 109) — sizes of towers.
     34 
     35 Output
     36 
     37 Print the number of operations needed to destroy all towers.
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 6  
     45 2 1 4 6 2 2
     46 ```
     47 
     48 Output
     49 
     50 ```
     51 3
     52 ```
     53 
     54 Input
     55 
     56 ```
     57 7  
     58 3 3 3 1 3 3 3
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 2
     65 ```
     66 
     67 Note
     68 
     69 The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color.
     70 
     71  ![](https://espresso.codeforces.com/03536e679d62748811026b5575567b66ad9c43b2.png)  After first operation there are four blocks left and only one remains after second operation. This last block is destroyed in third operation.