Codeforces Round #283 (Div. 2)-A. Minimum Difficulty (暴力)_html/css_WEB-ITnose

WBOY
풀어 주다: 2016-06-24 11:52:09
원래의
1111명이 탐색했습니다.

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?

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

31 4 6
로그인 후 복사

output

input

51 2 3 4 5
로그인 후 복사

output

input

51 2 3 7 8
로그인 후 복사

output

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.





题意:给一列n个数,让你选出删除一个中间值(第一个和最后一个不可删)之后,相邻两数之间的差值的最大值,问这个最大值最小可以是多少。


分析:暴力可解。枚举删除值的位置,每次求出间距的最大值即可。





AC代码:

#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;#define INF 0x7fffffffint a[105];int main(){    #ifdef sxk        freopen("in.txt","r",stdin);    #endif    int n;    while(scanf("%d",&n)!=EOF)    {        for(int i=0; i<n i scanf int ans="123456789;" for xx="0;" j="1;" x if a else> xx) ans = xx;        }        printf("%d\n", ans);    }    return 0;}</n></time.h></stdlib.h></math.h></string></map></set></queue></vector></algorithm></iostream></string.h></stdio.h>
로그인 후 복사


원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿