题库练习 Minimum Difficulty
← 上一题 下一题 →

A9707 | Minimum Difficulty

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Mike is trying rock climbing but he is awful at it.

There are $n$ holds on the wall, $i$ -th hold is at height $a_{i}$ off the ground. Besides, let the sequence $a_{i}$ increase, that is, $a_{i}<a_{i+1}$ for all $i$ from 1 to $n-1$ ; we will call such sequence a track. Mike thinks that the track $a_{1}$ , ..., $a_{n}$ has difficulty ![](/uploads/acgo/image/5a7a0f5267c4edcf_3e265bbd0f71.jpeg). In other words, difficulty equals the maximum distance between two holds that are adjacent in height.

Today Mike decided to cover the track with holds hanging on heights $a_{1}$ , ..., $a_{n}$ . To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence $(1,2,3,4,5)$ and remove the third element from it, we obtain the sequence $(1,2,4,5)$ ). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions.

Help Mike determine the minimum difficulty of the track after removing one hold.

输入格式

Mike is trying rock climbing but he is awful at it.

There are $n$ holds on the wall, $i$ -th hold is at height $a_{i}$ off the ground. Besides, let the sequence $a_{i}$ increase, that is, $a_{i}<a_{i+1}$ for all $i$ from 1 to $n-1$ ; we will call such sequence a track. Mike thinks that the track $a_{1}$ , ..., $a_{n}$ has difficulty ![](/uploads/acgo/image/78378616d6790af8_cc22c5ad8177.jpeg). In other words, difficulty equals the maximum distance between two holds that are adjacent in height.

Today Mike decided to cover the track with holds hanging on heights $a_{1}$ , ..., $a_{n}$ . To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence $(1,2,3,4,5)$ and remove the third element from it, we obtain the sequence $(1,2,4,5)$ ). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions.

Help Mike determine the minimum difficulty of the track after removing one hold.

输出格式

Print a single number — the minimum difficulty of the track after removing a single hold.

输入输出样例

输入 #1
3
1 4 6
输出 #1
5
输入 #2
5
1 2 3 4 5
输出 #2
2
输入 #3
5
1 2 3 7 8
输出 #3
4
C++ 编辑器
输入
输出