305031: CF955E. Icicles
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Icicles
题意翻译
- 有一洞穴长为 $n$,每个位置 $i$ 上都有一个冰锥,高度为 $a_i$。 - Krakozyabra 在 $0$ 时刻位于 $\frac{1}{2}$ 处,且以 $1$ 单位 / 时刻的速度向右移动。 - 你可以在 $0$ 时刻,在 $[1,n]$ 的任意位置放出一道向**左右**以 $1$ 单位 / 时刻的速度传播的声波。 - 在每个时刻开始时,Krakozyabra 会先向右移动,然后所有已经接触了声波的冰锥向下移动 $1$ 单位,最后声波向左右传播(也就是说,在该时刻接触声波的冰锥会在下一时刻下落)。 - 当冰锥的高度为 $0$ 时,冰锥会阻塞这一格并阻止 Krakozyabra 经过。 - 求最少经过多少时刻可以使 Krakozyabra 被**困在两块冰锥之间**(对冰锥的位置无要求)。无解输出 `-1`。 - $2\leq n\leq 10^5$,$1\leq a_i\leq 10^5$。题目描述
Andrew's favourite Krakozyabra has recenly fled away and now he's eager to bring it back! At the moment the refugee is inside an icy cave with $ n $ icicles dangling from the ceiling located in integer coordinates numbered from $ 1 $ to $ n $ . The distance between floor and the $ i $ -th icicle is equal to $ a_{i} $ . Andrew is free to choose an arbitrary integer point $ T $ in range from $ 1 $ to $ n $ inclusive and at time instant $ 0 $ launch a sound wave spreading into both sides (left and right) at the speed of one point per second. Any icicle touched by the wave starts falling at the same speed (that means that in a second the distance from floor to icicle decreases by one but cannot become less that zero). While distance from icicle to floor is more than zero, it is considered passable; as soon as it becomes zero, the icicle blocks the path and prohibits passing. Krakozyabra is initially (i.e. at time instant $ 0 $ ) is located at point ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF955E/6201067a97da7a97c457211e210f5a8e998bdde9.png) and starts running in the right direction at the speed of one point per second. You can assume that events in a single second happen in the following order: first Krakozyabra changes its position, and only then the sound spreads and icicles fall; in particular, that means that if Krakozyabra is currently at point ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF955E/1c5af17636ba64dd5732c7aa8ec584757d0bd2cf.png) and the falling (i.e. already touched by the sound wave) icicle at point $ i $ is $ 1 $ point from the floor, then Krakozyabra will pass it and find itself at ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF955E/698ff77408e1322df2c02364658180d6abdd0230.png) and only after that the icicle will finally fall and block the path. Krakozyabra is considered entrapped if there are fallen (i.e. with $ a_{i}=0 $ ) icicles both to the left and to the right of its current position. Help Andrew find the minimum possible time it takes to entrap Krakozyabra by choosing the optimal value of $ T $ or report that this mission is impossible.输入输出格式
输入格式
The first line contains the number of icicles $ n $ $ (2<=n<=10^{5}) $ . The next line contains $ n $ space-separated numbers $ a_{i} $ $ (1<=a_{i}<=10^{5}) $ — the distances from floor to icicles.
输出格式
Print an only integer — the minimum time it takes to entrap Krakozyabra between two fallen icicles. If it is impossible, print $ -1 $ .
输入输出样例
输入样例 #1
5
1 4 3 5 1
输出样例 #1
3
输入样例 #2
4
1 2 1 1
输出样例 #2
2
输入样例 #3
2
2 1
输出样例 #3
3
输入样例 #4
2
1 2
输出样例 #4
-1