102351: [AtCoder]ABC235 B - Climbing Takahashi

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $200$ points

Problem Statement

There are $N$ platforms arranged in a row. The height of the $i$-th platform from the left is $H_i$.

Takahashi is initially standing on the leftmost platform.

Since he likes heights, he will repeat the following move as long as possible.

  • If the platform he is standing on is not the rightmost one, and the next platform to the right has a height greater than that of the current platform, step onto the next platform.

Find the height of the final platform he will stand on.

Constraints

  • $2 \leq N \leq 10^5$
  • $1 \leq H_i \leq 10^9$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$
$H_1$ $\ldots$ $H_N$

Output

Print the answer.


Sample Input 1

5
1 5 10 4 2

Sample Output 1

10

Takahashi is initially standing on the leftmost platform, whose height is $1$. The next platform to the right has a height of $5$ and is higher than the current platform, so he steps onto it.

He is now standing on the $2$-nd platform from the left, whose height is $5$. The next platform to the right has a height of $10$ and is higher than the current platform, so he steps onto it.

He is now standing on the $3$-rd platform from the left, whose height is $10$. The next platform to the right has a height of $4$ and is lower than the current platform, so he stops moving.

Thus, the height of the final platform Takahashi will stand on is $10$.


Sample Input 2

3
100 1000 100000

Sample Output 2

100000

Sample Input 3

4
27 1828 1828 9242

Sample Output 3

1828

Input

题意翻译

输入 $N$ 个整数,求从左往右第一个大于等于右边数的数。

Output

分数:$200$分

问题描述

有$N$个平台排成一行。从左数起第$i$个平台的高度为$H_i$。

一开始,Takahashi站在最左边的平台上。

因为他喜欢高处,只要有可能,他就会重复以下动作。

  • 如果他所站的平台不是最右边的平台,且他右边的下一个平台的高度大于当前平台的高度,那么就走到下一个平台上。

找出他最后所站平台的高度。

限制条件

  • $2 \leq N \leq 10^5$
  • $1 \leq H_i \leq 10^9$
  • 输入中的所有值都是整数。

输入

从标准输入按以下格式获取输入:

$N$
$H_1$ $\ldots$ $H_N$

输出

输出答案。


样例输入1

5
1 5 10 4 2

样例输出1

10

Takahashi一开始站在最左边的平台上,其高度为$1$。他右边的下一个平台的高度为$5$,高于当前平台,所以他走到这个平台上。

他现在站在从左数起第$2$个平台上,其高度为$5$。他右边的下一个平台的高度为$10$,高于当前平台,所以他走到这个平台上。

他现在站在从左数起第$3$个平台上,其高度为$10$。他右边的下一个平台的高度为$4$,低于当前平台,所以他停止移动。

因此,Takahashi最后所站的平台的高度为$10$。


样例输入2

3
100 1000 100000

样例输出2

100000

样例输入3

4
27 1828 1828 9242

样例输出3

1828

加入题单

算法标签: