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

Sample test(s)
Input
3
1 4 6
Output
5
Input
5
1 2 3 4 5
Output
2
Input
5
1 2 3 7 8
Output
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.

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1001
const int inf=0x7fffffff; //无限大
int h[maxn];
int main()
{
int n;
cin>>n;
cin>>h[];
int minn=;
for(int i=;i<n-;i++)
{
cin>>h[i];
minn=max(h[i]-h[i-],minn);
}
cin>>h[n-];
minn=max(h[n-]-h[n-],minn);
//cout<<minn<<endl;
int kiss=;
for(int i=;i<n;i++)
{
kiss=min(h[i]-h[i-],kiss);
}
//cout<<kiss<<endl;
cout<<max(kiss,minn)<<endl;
return ;
}

最新文章

  1. 如何使用DOS命令(cd命令)
  2. 如何用jenkins实现自动化构建新版本和二维码下载
  3. shell 简单的比大小脚本
  4. DDD~领域事件与事件总线
  5. 如何获取有性能问题的SQL
  6. [python爬虫] Selenium定向爬取虎扑篮球海量精美图片
  7. Inno Setup使用技巧
  8. SQL数据库基础(五)
  9. Stockbroker Grapevine(floyd)
  10. USACO Section 2.4: Fractions to Decimals
  11. MySQL数据库InnoDB存储引擎中的锁机制
  12. webbrowser代理c#代码实现
  13. Android进阶笔记12:Manymo(在线安卓系统模拟器工具)
  14. MFC 仿QQ聊天软件(黄花寒)
  15. (七)Angularjs - 控制器
  16. Java内部类和外部类的通信探索
  17. Fedora15下搭建QT开发环境及编译QT
  18. Spring从认识到细化了解
  19. Object.is()
  20. Python 升级致yum 问题,pip 异常

热门文章

  1. 【内核】linux内核启动流程详细分析【转】
  2. asp.net mvc发送邮件
  3. 【转载】ajaxFileUpload 报这错jQuery.handleError is not a function
  4. Python-Web框架的本质
  5. [问题解决]同时显示多个Notification时PendingIntent的Intent被覆盖?
  6. PHP获得用户的真实IP地址
  7. phpStudy配置https
  8. virtualenv,virtualenvwrapper安装及使用
  9. Unix IPC之Posix消息队列(1)
  10. 左列動態添加菜單Repeater