Codeforces Round #283 (Div. 2)

Source: Internet
Author: User

 A. Minimum difficulty 

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

There isNHolds on the wall,I-th hold are at height a i  off the ground. Besides, let the Sequence  a i   increase, that is,  a I < a i + 1 for all  i from 1 to  n -1; We'll call such sequence A track. Mike thinks that the Track  a 1, ...,   a n  has  difficulty . In other words, difficulty equals the maximum distance between and holds that is adjacent in height.

a 1, ...,   a n . 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, 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≤ a I ≤1000), where ai am the height where the hold number i hangs. The sequence a increasing (i.e. each element except for the first one is strictly larg Er 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


Meaning: A non-incrementing array that defines the difficulty of this array as
Now to remove a number from this array (which must be removed), it is difficult to ask which number to take away from the array.


Idea: Record this array (the array itself does not record) 22 of the distance, and then find the minimum value of a[i]+a[i+1], is to remove the middle of this number, and then use this a[i]+a[i+1] and the original difficulty compared to the group, the big one is ans.

1#include <cstdio>2 Const intmaxn=104;3 intA[MAXN];4 intMain ()5 {6     intN;7      while(SCANF ("%d", &n)! =EOF)8     {9         intpre,p;Ten         inttot=1; Onescanf"%d",&pre); A          for(intI=2; i<=n;i++) -         { -scanf"%d",&p); thea[tot++]=p-Pre; -Pre=p; -         } -         intans=100000; +          for(intI=1; i<tot-1; i++) -         { +             if(a[i]+a[i+1]<ans) Aans=a[i]+a[i+1]; at         } -          for(intI=1; i<tot;i++) -         { -             if(a[i]>ans) -cn1=A[i]; -         } inprintf"%d\n", ans); -     } to     return 0; +}
15ms




Codeforces Round #283 (Div. 2)

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.