logo AlgoBeat OnlineJudge
登录 注册

#215710. [ICPC 2025 Jakarta R] Burning Blocks

内存限制:2048 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

William and his friends are on a camping trip and have gathered some wooden blocks. Before nightfall, they stack these wooden blocks into stacks from left to right. The -th stack has wooden blocks stacked on top of each other.

Each wooden block takes exactly one minute to burn. Once a wooden block is completely burnt, the fire will spread to all wooden blocks adjacent to it (the blocks immediately to its left, right, above, and below) and start burning them.

William starts burning from the outermost blocks, i.e. the blocks whose either left, right, or above side contains no blocks. Determine the total number of minutes required for all of the wood blocks to be completely burnt.

输入格式

The first line contains an integer ().

The second line contains integers representing (), the number of wooden blocks in each stack.

输出格式

A single line representing the number of minutes required for all blocks to be completely burnt.

样例

样例输入 1

5
2 3 4 2 3

样例输出 1

3

样例输入 2

13
2 5 6 6 4 3 4 3 1 2 4 8 4

样例输出 2

4

样例输入 3

3
1 0 2

样例输出 3

1

样例输入 4

1
0

样例输出 4

0

数据范围与提示

The following illustrates the burning process.

:::align{center} :::