CF1672I.PermutationForces
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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≤i≤∣p∣ and ∣i−pi∣≤s .
- For all j such that 1≤j≤∣p∣ and pi<pj , update pj to pj−1 .
- Delete the i -th element from p . Formally, update p to [p1,…,pi−1,pi+1,…,pn] .
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.
输入格式
The first line of input contains a single integer n ( 1≤n≤5⋅105 ) — the length of the permutation p .
The second line of input conatains n integers p1,p2,…,pn ( 1≤pi≤n ) — the elements of the permutation p .
It is guaranteed that all elements in p are distinct.
输出格式
Print the minimum strength s required.
输入输出样例
输入#1
3 3 2 1
输出#1
1
输入#2
1 1
输出#2
0
输入#3
10 1 8 4 3 7 10 6 5 9 2
输出#3
1
说明/提示
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−pi∣≤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.