博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #283 (Div. 2) A. Minimum Difficulty 暴力水题
阅读量:6976 次
发布时间:2019-06-27

本文共 2783 字,大约阅读时间需要 9 分钟。

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 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
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 1001const int inf=0x7fffffff; //无限大int h[maxn];int main(){ int n; cin>>n; cin>>h[0]; int minn=0; for(int i=1;i
>h[i]; minn=max(h[i]-h[i-1],minn); } cin>>h[n-1]; minn=max(h[n-1]-h[n-2],minn); //cout<
<

 

转载地址:http://ukupl.baihongyu.com/

你可能感兴趣的文章
我的友情链接
查看>>
我的友情链接
查看>>
华胜天成ivcs云系统初体验2
查看>>
MASQUERADE --random 端口不随机
查看>>
阿里云 Aliplayer高级功能介绍(二):缩略图
查看>>
从1.5K到18K 一个程序员的5年成长之路(二)
查看>>
从HelloWorld看Knative Serving代码实现
查看>>
制作一个简单的linux
查看>>
【ZooKeeper Notes 14】数据模型
查看>>
Expect自动化控制简单介绍
查看>>
我的友情链接
查看>>
Vmware虚拟机的复制后无法使用的问题和解决
查看>>
好程序员web前端技术分享媒体查询
查看>>
开博前的话
查看>>
【老孙随笔】注意啦,精神集中点儿!
查看>>
nagios监控shadow文件
查看>>
用Kotlin在IntelliJ Idea中无法生成 spring-configuration-metadata.json 文件
查看>>
企业数据库合规的最佳实践
查看>>
tar自动打包指定文件夹中的文件到指定目录
查看>>
修改Vim配色方案
查看>>