Maximization of Relational Expression (AOJ 0347) by ynu_a
Contest: 3420    RunID: 2277255    Status: Accepted    Date: Sun Apr 23 17:10:07 JST 2017


#include <iostream>
#include <algorithm>
#include<vector>
#include<stdio.h>

using namespace std;

int main() {
	
	int n;
	cin >> n;
	vector<int> array(n,0);
	
	for(int i = 0 ; i < n ; i++){
		cin >> array[i];
	}
	
	sort(array.begin(),array.end());
	
	int diff = 100000;
	int n1,n2;
	
	for(int i = 0;i < n -1 ; i++){
		int temp = array[i + 1] - array[i];
		if(temp < diff){
			diff = temp;
			n1 = i;
			n2 = i+1;
		}
	}
	int max ;
	
	for(int i = n-1; i > 0; i--){
		if(i == n1 || i-1 ==n1 || i == n2 || i-1 == n2){
			continue;
		}
		
		max = array[i] + array[i-1];
		break;
		
	}
	
	double ans = max / (double)diff;
	
	//最大値から
	max = array[n-1] + array[n-2];
	
	n1 = n-1;
	n2 = n-2;
	diff = 10000;
	
	for(int i = 0; i < n-3 ; i++){
		if(n1 == n && n2 == n && n1 == n-1 && n2 == n-1){
			continue;
		}
		int temp = array[i+1] - array[i];
		
		if(temp < diff){
			diff = temp;
		}
		
	}
	
	double ans2 = max / (double)diff;
	
	if(ans < ans2){
		printf("%.7lf\n",ans2);
		
	}else{
		printf("%.7lf\n",ans);
	}
	
	
	return 0;
}