# Codeforces Round #283 (Div. 2) A

Source: Internet
Author: User

Problem solving idea: give an increment sequence, A1,a2,a3,-----, an. Ask arbitrarily remove A2 to A3 any number between,

Since it is noted that the series is monotonically increasing, the maximum value of the difference between two adjacent items of the original sequence can be obtained first, Max,

To get a new sequence (such as removing A2 first), the maximum value of the difference between two adjacent items is Max1=findmax (MAX,A3-A1)

Then remove the A3 and get the maximum value of the difference between the two adjacent items Max2=findmax (MAX,A4-A2)

------

Then remove the an-1 and get the maximum value of the difference between the two adjacent items Maxn-2=findmax (max,an-an-2)

The minimum value of the max1,max2,max3,-----, maxn-2 is required by the title

A.

Minimum Difficulty

Time limit per test2 seconds

Memory limit per test256

Megabytes Inputstandard input Outputstandard output

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

There is n holds on the wall, i-th hold is at height ai off the ground. Besides, let the sequence AI increase, that's, Ai < AI + 1 for all I from 1 to n-1; We'll call such sequence a track. Mike thinks that's the track A1, ..., A has difficulty. In other words, difficulty equals the maximum distance between and holds that is 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's, 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 Adjac ENT holds after removing, the hold) to IS 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 for 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 was 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 C An remove-only-the second hold and then the sequence-looks like (1, 6), the maximum difference of the neighboring elements eq Uals 5.

The second test after removing every hold the difficulty equals 2.

In the third Test 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 <stdio.h>int searchmax (int a[],int n) {int i,max;max=a;for (i=2;i<=n;i++) {if (A[i]>max) max=a[i ];} return Max;} int searchmin (int a[],int n) {int i,min;min=a;for (i=2;i<=n;i++) {if (a[i]<min) min=a[i];} return min;} int Findmax (int a,int b) {if (a>b) return A;elsereturn B;} int main () {int a,d,e,i,n,s,j,k,max;while (scanf ("%d", &n)!=eof) {k=1;max=0;for (i=1;i<=n;i++) scanf ("%d", &a[i]); for (i=1;i<n;i++) D[k++]=a[i+1]-a[i];max=searchmax (d,n-1); J=1;for (i=2;i<=n-1;i++) {e[ J++]=findmax (max,a[i+1]-a[i-1]);//Find the maximum value     }printf ("%d\n", Searchmin (e,n-2)) of the difference between two adjacent items after the deletion of a number in the sequence;}}`

Codeforces Round #283 (Div. 2) A

Related Keywords:

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.