A8656 | Walking in the Rain
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of $n$ tiles that are lain in a row and are numbered from $1$ to $n$ from right to left. The opposition should start walking on the tile number $1$ and the finish on the tile number $n$ . During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number $i$ $(i<n-1)$ , you can reach the tiles number $i+1$ or the tile number $i+2$ from it (if you stand on the tile number $n-1$ , you can only reach tile number $n$ ). We can assume that all the opposition movements occur instantaneously.
In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the $i$ -th tile is destroyed after $a_{i}$ days of rain (on day $a_{i}$ tile isn't destroyed yet, and on day $a_{i}+1$ it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number $1$ is broken, or the tile number $n$ is broken, or it is impossible to reach the tile number $n$ from the tile number $1$ if we can walk on undestroyed tiles.
The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number $1$ to the tile number $n$ will be possible.
In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the $i$ -th tile is destroyed after $a_{i}$ days of rain (on day $a_{i}$ tile isn't destroyed yet, and on day $a_{i}+1$ it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number $1$ is broken, or the tile number $n$ is broken, or it is impossible to reach the tile number $n$ from the tile number $1$ if we can walk on undestroyed tiles.
The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number $1$ to the tile number $n$ will be possible.
输入格式
The first line contains integer $n$ ( $1<=n<=10^{3}$ ) — the boulevard's length in tiles.
The second line contains $n$ space-separated integers $a_{i}$ — the number of days after which the $i$ -th tile gets destroyed ( $1<=a_{i}<=10^{3}$ ).
The second line contains $n$ space-separated integers $a_{i}$ — the number of days after which the $i$ -th tile gets destroyed ( $1<=a_{i}<=10^{3}$ ).
输出格式
Print a single number — the sought number of days.
输入输出样例
输入 #1
4 10 3 5 10
输出 #1
5
输入 #2
5 10 2 8 3 5
输出 #2
5
In the first sample the second tile gets destroyed after day three, and the only path left is $1→3→4$ . After day five there is a two-tile gap between the first and the last tile, you can't jump over it.
In the second sample path $1→3→5$ is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.
In the second sample path $1→3→5$ is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted