QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 1024 MB 總分: 100

#4995. 最高山峰

统计

与挪威和冰岛等其他 NCPC 国家相比,瑞典的山脉可能并不算特别壮观,但至少比丹麦的平原要好。不过,在比较其他成员国时,情况就不那么明朗了。例如,爱沙尼亚比立陶宛多山吗?为了解决这个问题,你需要确定这两个国家中哪一个拥有最令人印象深刻的山峰。

一张 Suur Munamägi 的老照片,公有领域

山脉定义为对 $n$ 个等距点的高度 $h_i$ 进行采样。在山脉中,如果存在三个下标 $1 \le i < j < k \le n$ 满足 $h_i \le \dots \le h_j \ge \dots \ge h_k$,我们称其为一个山峰。山峰的高度定义为 $h_j - h_i$ 和 $h_j - h_k$ 中的较小值。

给定一个山脉,你能找出其最高山峰的高度吗?

输入格式

第一行包含一个整数 $N$ ($3 \le n \le 200\,000$),表示山脉采样点的数量。

第二行(也是最后一行)包含采样点的高度 $h_1, \dots, h_N$ ($0 \le h_i \le 318 \cdot 10^9$),单位为纳米(海拔高度)。

保证山脉中至少包含一个山峰。

输出格式

输出一个整数:最高山峰的高度。

样例

输入格式 1

11
0 1 2 3 4 5 4 3 2 1 0

输出格式 1

5

输入格式 2

10
29 85 88 12 52 37 19 86 7 44

输出格式 2

67

输入格式 3

3
2147483647 318000000000 2147483647

输出格式 3

315852516353

输入格式 4

3
1 1 1

输出格式 4

0

¹ 是的,但差距不大!立陶宛的最高点是 Aukštojas 山,海拔 293.84 米,而爱沙尼亚拥有波罗的海地区的最高峰:Suur Munamägi,海拔 318 米。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.