CF192B.Walking in the Rain

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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.

在贝尔兰,反对派计划在林荫道上举行大规模游行。该林荫道由 nn 块地砖组成,这些地砖排成一行,从右向左依次编号为 11 到 nn。反对派必须从编号为 11 的地砖出发,并在编号为 nn 的地砖结束游行。游行过程中,允许在相邻地砖之间从右向左移动,也可跳过一块地砖。更准确地说,若你当前站在编号为 ii 的地砖上(其中 i<n−1i < n - 1),则你可以到达编号为 i+1i + 1 或编号为 i+2i + 2 的地砖(若你站在编号为 n−1n - 1 的地砖上,则只能到达编号为 nn 的地砖)。我们可假设所有反对派的移动均瞬时完成。

为破坏此次反对派集会,贝尔兰血腥政权发动了降雨。林荫道上的地砖质量低劣,在雨中会迅速损毁。已知第 ii 块地砖将在连续降雨 aia_i 天后损毁(即第 aia_i 天结束时该地砖尚未损毁,而在第 ai+1a_i + 1 天开始时已损毁)。当然,任何人不得在已损毁的地砖上行走!因此,若出现以下任一情况,即视为此次游行被成功破坏:编号为 11 的地砖已损毁,或编号为 nn 的地砖已损毁,或在仅允许在未损毁地砖上行走的前提下,无法从编号为 11 的地砖到达编号为 nn 的地砖。

反对派希望为游行召集更多支持者。因此,他们准备时间越长越好。请帮助反对派计算他们还剩多少时间,并告诉我们:从编号为 11 的地砖走到编号为 nn 的地砖的游行,在多少天内仍可行。

输入格式

The first line contains integer n (1 ≤ n ≤ 103) — 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 ≤ 103).

第一行包含一个整数 nn(1≤n≤1031 \leq n \leq 10^3)—— 林荫道的长度(以瓷砖数量计)。

第二行包含 nn 个用空格分隔的整数 aia_i —— 第 ii 块瓷砖被摧毁所需的天数(1≤ai≤1031 \leq a_i \leq 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.

在第一个样例中,第二块瓷砖在第 3 天后被摧毁,唯一剩余的路径为 1 → 3 → 41 → 3 → 4。到第 5 天时,第一块与最后一块瓷砖之间出现了一个两格宽的空隙,无法跳跃通过。

在第二个样例中,路径 1 → 3 → 51 → 3 → 5 一直可用至第 5 天(含第 5 天)。第 6 天时,最后一块瓷砖被摧毁,行走因此受阻。

输入解题思路,AI测评打分。不知道怎么写?

首页