問題一覧 > 通常問題

No.484 Harvest

レベル : / 実行時間制限 : 1ケース 3.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 59
作問者 : ei1333333 / テスター : tanzaku
お気に入りにしたユーザー ProblemId : 1428 / 自分の提出
問題文最終更新日: 2026-06-25 22:24:13
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 156 (順位表) の他の問題:

Problem Statement

There are $N$ cells arranged in a horizontal row, numbered $1, 2, \dots, N$ from left to right.

Each cell has $1$ fruit tree planted in it, and it is known that the fruit of the tree in cell $i$ ripens at time $A_i$. Once a fruit has ripened, it does not disappear until it is harvested.

Tanuki-kun can start from any cell at time $0$. Since Tanuki-kun is not good at sudden movements, in each unit of time he can only either move to an adjacent cell or stay in his current cell. At any moment, he can harvest the ripened fruit of the tree in the cell he is in. Since Tanuki-kun is a harvesting professional, the time needed for harvesting can be ignored.

Tanuki-kun is hungry, so he wants to harvest the fruit of the trees in all cells as early as possible. Find the earliest time at which he can finish harvesting the fruit of the trees in all cells.

Input

$N$
$A_{1}\ A_{2}\ \dots\ A_{N}$

The $1$st line gives the number of cells $N(1 \le N \le 2\ 000)$.

The $2$nd line gives $N$ values separated by single spaces. The $i(1 \le i \le N)$-th of these values means that the fruit of the tree in cell $i$ ripens at time $A_i(0 \le A_i \le 10^9)$.

Output

Output, on 1 line, the earliest time at which Tanuki-kun can finish harvesting the fruit of the trees in all cells.

Print a newline at the end.

Sample

Sample 1
Input
3
0 1 1
Output
2

The fruit of the tree in cell $1$ ripens at time $0$, and the fruit of the trees in cells $2, 3$ ripens at time $1$.

For example, choose cell $1$ as the initial position.
At time $0$, he harvests the fruit of the tree in cell $1$.
At time $1$, he moves to cell $2$ and harvests the fruit of the tree in cell $2$.
At time $2$, he moves to cell $3$ and harvests the fruit of the tree in cell $3$.

This is the earliest time, so output $2$.

Sample 2
Input
3
5 1 4
Output
6

For example, choose cell $2$ as the initial position.
At time $0$, he stays where he is.
At time $1$, he harvests the fruit of the tree in cell $2$.
At time $2$, he moves to cell $3$.
At time $3$, he stays where he is.
At time $4$, he harvests the fruit of the tree in cell $3$.
At time $5$, he moves to cell $2$.
At time $6$, he moves to cell $1$ and harvests the fruit of the tree in cell $1$.

This is the earliest time, so output $6$.

Sample 3
Input
3
1333 1000000000 1333
Output
1000000000

It is necessary to wait a long time until the fruit of the tree in cell $2$ ripens.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。