A. Minimum Difficulty
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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

Examples
input
  1. 3
    1 4 6
output
  1. 5
input
  1. 5
    1 2 3 4 5
output
  1. 2
input
  1. 5
    1 2 3 7 8
output
  1. 4
Note

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.

【题意】:对一个数组,定义困难值是两个相邻元素之间差的最大值。
现在又一个数组,可以去掉任意一个元素,问剩余数列的困难值的最小值是多少。

【分析】:由于数据小,可以枚举去掉的元素然后暴力更新,复杂度是 O(nn)。如果数据比较大的话,可以利用动态规划O(n)过。

【代码】:

  1. #include <bits/stdc++.h>
  2. #define N 100010
  3. using namespace std;
  4. #define oo 99999
  5. int a[110];
  6. int b[110];
  7.  
  8. int main(){
  9. int n;
  10. cin>>n;
  11. for(int i=1;i<=n;i++){
  12. cin>>a[i];
  13. }
  14.  
  15. int ans=oo;
  16. for(int i=2;i<n;i++){
  17. int k=0;
  18. for(int j=1;j<=n;j++){
  19. if(j==i)continue;
  20. b[k++]=a[j];
  21. }
  22. int MAX=0;
  23. for(int j=0;j<n-1;j++){
  24. MAX=max(MAX,b[j+1]-b[j]);
  25. }
  26. ans=min(ans,MAX);
  27. }
  28. cout<<ans<<endl;
  29. return 0;
  30. }

  

Codeforces Round #283 (Div. 2) A. Minimum Difficulty【一个数组定义困难值是两个相邻元素之间差的最大值。 给一个数组,可以去掉任意一个元素,问剩余数列的困难值的最小值是多少】的更多相关文章

  1. Codeforces Round #283 (Div. 2) A. Minimum Difficulty 暴力水题

    A. Minimum Difficulty time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  2. 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns

    题目传送门 /* 题意:删除若干行,使得n行字符串成递增排序 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 */ /*********************** ...

  3. 构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination

    题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ...

  4. Codeforces Round #283 (Div. 2) A

    解题思路:给出一个递增数列,a1,a2,a3,-----,an.问任意去掉a2到a3之间任意一个数之后, 因为注意到该数列是单调递增的,所以可以先求出原数列相邻两项的差值的最大值max, 得到新的一个 ...

  5. Codeforces Round #283 (Div. 2) A ,B ,C 暴力,暴力,暴力

    A. Minimum Difficulty time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  6. Codeforces Round #283 (Div. 2)

    A:暴力弄就好,怎么方便怎么来. B:我们知道最多加10次, 然后每次加1后我们求能移动的最小值,大概O(N)的效率. #include<bits/stdc++.h> using name ...

  7. Codeforces Round #411 div 2 D. Minimum number of steps

    D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input st ...

  8. Codeforces Round #283 (Div. 2) C. Removing Columns 暴力

    C. Removing Columns time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #555 (Div. 3) E. Minimum Array 【数据结构 + 贪心】

    一 题面 E. Minimum Array 二 分析 注意前提条件:$0 \le  a_{i} \lt n$ 并且 $0 \le  b_{i} \lt n$.那么,我们可以在$a_{i}$中任取一个数 ...

随机推荐

  1. C# 检测真实的文件类型函数

    private bool IsAllowedExtension(HttpPostedFile hifile) { bool ret = false; System.IO.FileStream fs = ...

  2. hadoop2.x 完全分布式详细集群搭建(图文:4台机器)

    在准备之前说一下本次搭建的各节点角色,进程. nameNode 进程:NameNode dataNode  进程:DataNode resourceManager :ResourceManager n ...

  3. 关于Canvas的坐标系

    注意Canvas的坐标系应该是这样子的: 看下面的例子: 最后的显示效果是:

  4. Django项目:CRM(客户关系管理系统)--65--55PerfectCRM实现CRM客户报名状态颜色变化

    # kingadmin.py # ————————04PerfectCRM实现King_admin注册功能———————— from crm import models #print("ki ...

  5. pycharm每次新建项目都要重新安装一些第三方库的解决办法(转载防删)

    目前有三个解决办法,也是亲测有用的: 第一个方法:因为之前有通过pycharm的project interpreter里的+号添加过一些库,但添加的库只是指定的项目用的,如果想要用,就必须用之前的项目 ...

  6. 简单linux查询

    1查看日志异常 tailf nohup.out|grep ERROR -A 3 --color   tailf nohup.out|grep ERROR|grep chunk -A 3 -B 3 -- ...

  7. [原创]Machine Learning/机器学习 文章合集

    转载请注明出处:https://www.codelast.com/ ➤ 用人话解释机器学习中的Logistic Regression(逻辑回归) ➤ 如何防止softmax函数上溢出(overflow ...

  8. Luogu P1273 有线电视网(树形dp+背包)

    P1273 有线电视网 题面 题目描述 某收费有线电视网计划转播一场重要的足球比赛.他们的转播网和用户终端构成一棵树状结构,这棵树的根结点位于足球比赛的现场,树叶为各个用户终端,其他中转站为该树的内部 ...

  9. 跟我一起做一个vue的小项目(八)

    接下来我们进行的是城市选择页面的路由配置 添加city.vue,使其点击城市,然后跳转到city页面 //router.js import Vue from 'vue' import Router f ...

  10. 状态压缩中常用的位运算(DP)

    面对位运算,一直很无感...可能数学太差,脑洞太小. 1.首先是最基本的: 与&,或|,非~,异或^. 2.获取一个或者多个固定位的值: 假设 x = 1010(二进制),我们要取左数第二位的 ...