Codeforces 496A. Minimum Difficulty, codeforces496a

Source: Internet
Author: User

Codeforces 496A. Minimum Difficulty, codeforces496a



A. Minimum Difficultytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Mike is trying rock climbing but he is awful at it.

There areNHolds on the wall,I-Th hold is at heightAIOff the ground. Besides, let the sequenceAIIncrease, that is,AILatency <latencyAILifecycle + lifecycle 1 for allIFrom 1NAudio-extract 1; we will call such sequence a track. Mike thinks that the trackA1 ,...,ANHas 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 heightsA1 ,...,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, limit 2, limit 3, when 4, then 5) and remove the third element from it, we obtain the sequence (1, then 2, then 4, then 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 integerN(3 cores ≤ CoresNMemory ≤ memory 100)-the number of holds.

The next line containsNSpace-separated integersAI(1 digit ≤ DigitAILimit ≤ limit 1000), whereAIIs the height where the hold numberIHangs. The sequenceAIIs increasing (I. e. each element should t 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
5
Input
51 2 3 4 5
Output
2
Input
51 2 3 7 8
Output
4
Note

In the first sample you can remove only the second hold, then the sequence looks like (1, limit 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, latency 3, latency 7, latency 8), (1, latency 2, latency 7, latency 8), (1, latency 2, limit 3, limit 8), for which the difficulty is 4, 5 and 5, respectively. thus, after removing the second element we obtain the optimal answer-4.



n = int(raw_input())a = map(int,raw_input().split(' '))ans = -1for i in range(1,n-1):temp = 0for j in range(1,n):if j==i :continueelif j-1==i:temp = max(temp,a[j]-a[j-2])else :temp = max(temp,a[j]-a[j-1])if ans == -1 :  ans = tempans = min(ans,temp)print ans



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.