CF 474A - Keyboard
Mike is trying rock climbing but he is awful at it.
There are n holds on the wall, i-th hold is at height ai off the ground. Besides, let the sequence ai increase, that is, ai < ai + 1 for all i from 1 to n - 1; we will call such sequence a track. Mike thinks that the track a1, ..., an has difficulty . 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 a1, ..., an. 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.
Input
The first line contains a single integer n (3 ≤ n ≤ 100) — the number of holds.
The next line contains n space-separated integers ai (1 ≤ ai ≤ 1000), where ai is the height where the hold number i hangs. The sequence ai is increasing (i.e. each element except for the first one is strictly larger than the previous one).
Output
Print a single number — the minimum difficulty of the track after removing a single hold.
-----------------------------------------
迈克正在尝试攀岩,但他的表现很糟糕。
墙上有 n 个据点,第 i 个据点位于距地面高度 ai 处。 另外,让序列ai递增,即对于所有i从1到n - 1,ai < ai + 1; 我们将这样的序列称为轨道。 Mike 认为轨道 a1, ..., an 有困难。 换句话说,难度等于高度相邻的两个点之间的最大距离。
今天,迈克决定用悬挂在高度 a1, ..., an 上的支撑点覆盖赛道。 为了使问题变得更难,Mike 决定删除一个保留,即删除序列中的一个元素(例如,如果我们采用序列 (1, 2, 3, 4, 5) 并从中删除第三个元素, 我们得到序列 (1, 2, 4, 5))。 然而,由于 Mike 的攀爬能力很差,他希望在所有可能的移除抓点的选项中,最终的难度(即移除抓点后相邻抓点之间的最大高度差)尽可能小。 第一个和最后一个保持点必须保持在原来的位置。
帮助迈克确定取消一个握点后赛道的最低难度。
输入
第一行包含一个整数 n (3 ≤ n ≤ 100) — 保持的数量。
下一行包含 n 个空格分隔的整数 ai (1 ≤ ai ≤ 1000),其中 ai 是保持编号 i 悬挂的高度。 序列 ai 正在增加(即除了第一个元素之外的每个元素都严格大于前一个元素)。
输出
打印一个数字——移除单个支撑后赛道的最低难度。
---------------------------------------------
每次保存2个变量,然后根据变量去处理即可。