CF192B.Walking in the Rain

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of nn tiles that are lain in a row and are numbered from 11 to nn from right to left. The opposition should start walking on the tile number 11 and the finish on the tile number nn . 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 ii (i<n-1) , you can reach the tiles number i+1i+1 or the tile number i+2i+2 from it (if you stand on the tile number n1n-1 , you can only reach tile number nn ). 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 ii -th tile is destroyed after aia_{i} days of rain (on day aia_{i} tile isn't destroyed yet, and on day ai+1a_{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 11 is broken, or the tile number nn is broken, or it is impossible to reach the tile number nn from the tile number 11 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 11 to the tile number nn will be possible.

输入格式

The first line contains integer nn ( 1<=n<=1031<=n<=10^{3} ) — the boulevard's length in tiles.

The second line contains nn space-separated integers aia_{i} — the number of days after which the ii -th tile gets destroyed ( 1<=ai<=1031<=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 1341→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 1351→3→5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.

首页