CF496A.Minimum Difficulty

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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 . 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.

迈克正在尝试攀岩,但他在这方面非常糟糕。

墙上共有 nn 个支点,其中第 ii 个支点距离地面的高度为 aia_i。此外,设序列 aia_i 是严格递增的,即对所有从 11 到 n−1n-1 的 ii,均有 ai<ai+1a_i < a_{i+1};我们将这样的序列称为一条“路线”。迈克认为路线 a1,…,ana_1, \dots, a_n 的难度为 。换言之,难度等于相邻支点(按高度排序)之间最大高度差。

今天,迈克决定在高度 a1,…,ana_1, \dots, a_n 处设置支点以构成该路线。为了增加挑战性,他决定移除其中一个支点,即从序列中删去一个元素(例如,若取序列 (1, 2, 3, 4, 5)(1,\,2,\,3,\,4,\,5) 并删去第三个元素,则得到序列 (1, 2, 4, 5)(1,\,2,\,4,\,5))。然而,由于迈克攀岩水平极差,他希望在所有可能的移除方案中,使最终路线的难度(即移除一个支点后,相邻支点之间的最大高度差)尽可能小。注意:第一个和最后一个支点必须保留在原位置。

请帮助迈克计算移除一个支点后所能达到的最小难度。

输入格式

The first line contains a single integer n (3 ≤ n ≤ 100) — the number of holds.

The next line contains n space-separated integers a__i (1 ≤ a__i ≤ 1000), where a__i is the height where the hold number i hangs. The sequence a__i is increasing (i.e. each element except for the first one is strictly larger than the previous one).

第一行包含一个整数 nn(3≤n≤1003 \leq n \leq 100)—— 表示支点的数量。

下一行包含 nn 个用空格分隔的整数 aia_i(1≤ai≤10001 \leq a_i \leq 1000),其中 aia_i 表示第 ii 个支点悬挂的高度。序列 aia_i 是严格递增的(即除第一个元素外,每个元素都严格大于前一个元素)。

输出格式

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

说明/提示

In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.

In the second test after removing every hold the difficulty equals 2.

In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer — 4.

在第一个样例中,你只能移除第二个支点,此时序列为 (1, 6)(1,\ 6),相邻元素的最大差值为 55。

在第二个测试用例中,移除所有支点后,难度值为 22。

在第三个测试用例中,你可以得到序列 (1, 3, 7, 8)(1,\ 3,\ 7,\ 8)、(1, 2, 7, 8)(1,\ 2,\ 7,\ 8)、(1, 2, 3, 8)(1,\ 2,\ 3,\ 8),其对应的难度值分别为 44、55 和 55。因此,移除第二个元素后可得到最优答案——44。

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

首页