496A. Minimum Difficulty

Problem Link

Source Code

#include<bits/stdc++.h>
using namespace std;
int main()
{
int i=0,n,a=0,b=10000;
cin>>n;
int ar[n];
for(i=0;i<n;i++)
cin>>ar[i];
sort(ar,ar+n);
int dif=0;
int sum=0;
for(i=1;i<n;i++)
{
a=max(a,ar[i]-ar[i-1]);

}
for(i=1;i<n-1;i++)
    b=min(b,max(ar[i+1]-ar[i-1],a));
cout<<b<<endl;
}
Advertisements

About waprogramming

I am in CSE,from CUET
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s