Codeforces Global Round 20
I
PermutationForces
Codeforces
3000
原题
← H→
翻译中…

You have a permutation $p$ of integers from $1$ to $n$.

翻译中…

You have a strength of $s$ and will perform the following operation some times:

翻译中…
  • Choose an index $i$ such that $1 \leq i \leq |p|$ and $|i-p_i| \leq s$.
  • For all $j$ such that $1 \leq j \leq |p|$ and $p_i \lt p_j$, update $p_j$ to $p_j-1$.
  • Delete the $i$-th element from $p$. Formally, update $p$ to $[p_1,\ldots,p_{i-1},p_{i+1},\ldots,p_n]$.
翻译中…

It can be shown that no matter what $i$ you have chosen, $p$ will be a permutation of integers from $1$ to $|p|$ after all operations.

翻译中…

You want to be able to transform $p$ into the empty permutation. Find the minimum strength $s$ that will allow you to do so.

翻译中…

Input

翻译中…

The first line of input contains a single integer $n$ ($1 \leq n \leq 5 \cdot 10^5$)  — the length of the permutation $p$.

翻译中…

The second line of input conatains $n$ integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq n$)  — the elements of the permutation $p$.

翻译中…

It is guaranteed that all elements in $p$ are distinct.

翻译中…

Output

翻译中…

Print the minimum strength $s$ required.

翻译中…

Note

翻译中…

In the first test case, the minimum $s$ required is $1$.

翻译中…

Here is how we can transform $p$ into the empty permutation with $s=1$:

翻译中…
  • In the first move, you can only choose $i=2$ as choosing any other value of $i$ will result in $|i-p_i| \leq s$ being false. With $i=2$, $p$ will be changed to $[2,1]$.
  • In the second move, you choose $i=1$, then $p$ will be changed to $[1]$.
  • In the third move, you choose $i=1$, then $p$ will be changed to $[~]$.
翻译中…

It can be shown that with $s=0$, it is impossible to transform $p$ into the empty permutation.

翻译中…

样例

Input #1
3
3 2 1
Output #1
1
InputCopy OutputCopy
Input #2
1
1
Output #2
0
InputCopy OutputCopy
Input #3
10
1 8 4 3 7 10 6 5 9 2
Output #3
1
InputCopy OutputCopy
题目信息
题号
1672I
时间限制
5 s
内存限制
1024 MB
标签
数据结构
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。