Problem:
有理式最大化
N
個の異なる自然数が与えられる。その中から異なる４つを選んで、それらを $A$, $B$, $C$, $D$ としたとき、次の数式
$\frac{A + B}{C - D}$
の最大値を求めたい。
N
個の異なる自然数が与えられたとき、その中から異なる４つを選んで、上の数式の最大値を求めるプログラムを作成せよ。
Input
入力は以下の形式で与えられる。
N
a
1
a
2
...
a
N
１行目に自然数の個数
N
(4 ≤
N
≤ 1000) が与えられる。２行目に各自然数の値
a
i
(1 ≤
a
i
≤ 10
8
) が与えられる。ただし、同じ自然数が重複して現れることはない（
i
≠
j
について
a
i
≠
a
j
)。
Output
与えられた
N
個の自然数に対して、上の数式の最大値を実数で出力する。ただし、誤差がプラスマイナス 10
-5
を超えてはならない。
Sample Input 1
10
1 2 3 4 5 6 7 8 9 10
Sample Output 1
19.00000
入力例１では、$A=9$, $B=10$, $C=2$, $D=1$ などの組み合わせで最大になる。
Sample Input 2
5
22 100 42 3 86
Sample Output 2
9.78947
入力例２では、$A=100$, $B=86$, $C=22$, $D=3$ などの組み合わせで最大になる。
Sample Input 3
6
15 21 36 10 34 5
Sample Output 3
18.00000
入力例３では、$A=21$, $B=15$, $C=36$, $D=34$ などの組み合わせで最大になる。
Sample Input 4
4
100000 99999 8 1
Sample Output 4
28571.285714

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int n;
    cin>>n;
    vector<int> s(n);
    for(int i=0;i<n;i++) cin>>s[i];
    sort(s.begin(),s.end());
    multiset<int> st;
    for(int i=0;i<n;i++) st.insert(s[i]);
    double ans = 0;
    for(int i=0;i<n;i++)for(int j=i+1;j<n;j++){
        double t = s[j]-s[i];
        st.erase(st.find(s[i]));
        st.erase(st.find(s[j]));
        int a = *st.rbegin();
        st.erase(st.find(a));
        int b = *st.rbegin();
        ans = max(ans,(a+b)/t);
        st.insert(a);
        st.insert(s[i]);
        st.insert(s[j]);
    }
    cout<<fixed<<setprecision(14)<<ans<<endl;
}
accuracy: 1
time_ms: 70
memory_kb: 3584
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define DB(x) cout<<#x<<'='<<x<<endl;

using P = pair<int,int>;

int N;
vector<int>a;
int main(){
	cin>>N;
	for(int i=0;i<N;++i){
		int aa;cin>>aa;
		a.push_back(aa);
	}
	vector<P>sum,dif;
	for(int i=0;i<N;++i)for(int j=0;j<N;++j)if(a[i]<a[j]){
		sum.push_back({a[i],a[j]});dif.push_back({a[i],a[j]});
	}
	sort(sum.begin(),sum.end(),[](const P&p1,const P&p2){
		return p1.first+p1.second<p2.first+p2.second;
	});
	sort(dif.begin(),dif.end(),[](const P&p1,const P&p2){
		return -p1.first+p1.second<-p2.first+p2.second;
	});
	long double ans = 0.0;
	for(auto p : sum){
		int A=p.first,B=p.second;
		int C=0,D=0;
		for(auto q : dif){
			if(q.first!=A&&q.first!=B&&q.second!=A&&q.second!=B){
				C=q.second;
				D=q.first;
				break;
			}
		}
		ans = max(ans,((long double)A+B) / (C-D));
	}
	cout.precision(15);
	cout<<ans<<endl;
	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 13072
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define DB(x) cout<<#x<<'='<<x<<endl;

using P = pair<int,int>;

int N;
vector<int>a;
int main(){
	cin>>N;
	for(int i=0;i<N;++i){
		int aa;cin>>aa;
		a.push_back(aa);
	}
	vector<P>sum,dif;
	for(int i=0;i<N;++i)for(int j=0;j<N;++j)if(a[i]<a[j]){
		sum.push_back({a[i],a[j]});dif.push_back({a[i],a[j]});
	}
	sort(sum.begin(),sum.end(),[](const P&p1,const P&p2){
		return p1.first+p1.second<p2.first+p2.second;
	});
	sort(dif.begin(),dif.end(),[](const P&p1,const P&p2){
		return -p1.first+p1.second<-p2.first+p2.second;
	});
	long double ans = 0.0;
	for(auto p : sum){
		int A=p.first,B=p.second;
		int C=0,D=0;
		for(auto q : dif){
			if(q.first!=A&&q.first!=B&&q.second!=A&&q.second!=B){
				C=q.second;
				D=q.first;
				break;
			}
		}
		ans = max(ans,((long double)A+B) / (C-D));
	}
	cout.precision(15);
	cout<<ans<<endl;
	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 12700
final_rank: 13

code_snippet: #line 1 "/opt/library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'001'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
#define inf infty<ll>

using pi = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

#define rep1(a) for (ll _ = 0; _ < (ll)(a); ++_)
#define rep2(i, a) for (ll i = 0; i < (ll)(a); ++i)
#define rep3(i, a, b) for (ll i = a; i < (ll)(b); ++i)
#define rep4(i, a, b, c) for (ll i = a; i < (ll)(b); i += (c))
#define rrep1(a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep2(i, a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep3(i, a, b) for (ll i = (b)-1; i >= (ll)(a); --i)
#define rrep4(i, a, b, c) for (ll i = (b)-1; i >= (ll)(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)

#define all(x) (x).begin(),(x).end()
#define len(x) (ll)(x.size())
#define elif else if
#define bit(x, i) (((x)>>(i))&1)

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll
#define abs llabs

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

ll popcnt(ll x) { return __builtin_popcountll(x); }
ll popcnt(u64 x) { return __builtin_popcountll(x); }
ll popcnt_mod_2(ll x) { return __builtin_parityll(x); }
ll popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
ll topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
ll lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template<typename T> T SUM(const vector<T> &A) {
  T s = 0; for (auto &&a: A) s += a;
  return s;
}

template <typename T>
T POP(queue<T> &que) {
  T a = que.front();
  que.pop();
  return a;
}
template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    (check(x) ? ok : ng) = x;
  }
  return ok;
}
template <typename F>
f128 binary_search_real(F check, f128 ok, f128 ng, ll iter = 100) {
  rep(iter) {
    f128 x = (ok + ng) / 2;
    (check(x) ? ok : ng) = x;
  }
  return (ok + ng) / 2;
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  rep(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vc<T> cumsum(vc<U> &A, ll off = 1) {
  ll N = A.size();
  vc<T> B(N + 1);
  rep(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vi argsort(const vector<T> &A) {
  vi ids(len(A));
  iota(all(ids), 0);
  sort(all(ids),
       [&](ll i, ll j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vi &I) {
  vc<T> B(len(I));
  rep(i, len(I)) B[i] = A[I[i]];
  return B;
}

template<typename T> inline bool chmax(T &a, T b) {return ((a<b)?(a=b,true):(false));}
template<typename T> inline bool chmin(T &a, T b) {return ((a>b)?(a=b,true):(false));}

inline void wt(const char c) { cout << c; }
inline void wt(const string s) { cout << s; }
inline void wt(const char *s) { cout << s; }

template <typename T>
void wt_integer(T x) {
  cout << (x);
}
template <typename T>
void wt_real(T x) {
  cout << fixed << setprecision(15) << (long double)(x);
}
template <typename T>
void wt_integer128(T x) {
  char buf[64];
  char *d = end(buf);
  d--; *d = '\0';
  __uint128_t tmp = ((x < 0)? -x : x);
  do {
    d--; *d = char(tmp%10 + '0'); tmp /= 10;
  } while (tmp);
  if (x < 0) {
    d--; *d = '-';
  }
  cout << d;
}

inline void wt(int x) { wt_integer(x); }
inline void wt(ll x) { wt_integer(x); }
inline void wt(i128 x) { wt_integer128(x); }
inline void wt(u32 x) { wt_integer(x); }
inline void wt(u64 x) { wt_integer(x); }
inline void wt(u128 x) { wt_integer128(x); }
inline void wt(double x) { wt_real(x); }
inline void wt(long double x) { wt_real(x); }
inline void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first); wt(' '); wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
void onez(bool t = 1) { print(t ? 1 : 0); }
#define endl '\n'
#define dump(x) {cerr << #x " = " << x << '\n';}
#line 2 "main.cpp"

int solve();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  while (!solve()) {break;}
  return 0;
}

int solve() {
  ll N;
  cin >> N;
  vi a(N);
  rep(i, N) cin >> a[i];
  sort(all(a));
  vc<tuple<ll,ll,ll>> b;
  rep(i, N-1) rep(j, i+1, N) b.eb(mt(abs(a[i]-a[j]), i, j));
  sort(all(b));
  double ans = 0;
  rep(i, N-1) rep(j, i+1, N) {
    ll A = a[i];
    ll B = a[j];
    rep(k, len(b)) {
      if (get<1>(b[k]) == i) continue;
      if (get<1>(b[k]) == j) continue;
      if (get<2>(b[k]) == i) continue;
      if (get<2>(b[k]) == j) continue;
      ll CD = get<0>(b[k]);
      chmax(ans, double(A+B) / CD);
      break;
    }
  }
  print(ans);
  return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 16944
final_rank: 17

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 0347.cc: Maximizing Rational Expression
 */

#include<cstdio>
#include<vector>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 1000;
const int INF = 1 << 29;

/* typedef */

struct Elm {
  int l, r, d;
  Elm() {}
  Elm(int _x): l(_x), r(_x), d(INF) {}
  Elm(int _l, int _r, int _d): l(_l), r(_r), d(_d) {}

  Elm operator+(const Elm &e) const {
    if (l >= INF) return e;
    if (e.l >= INF) return *this;
    return Elm(l, e.r, min(e.l - r, min(d, e.d)));
  }
};

template <typename T>
struct SegTreeSum {
  int e2;
  vector<T> nodes;
  T defv;
  SegTreeSum() {}

  void init(int n, T _defv) {
    defv = _defv;
    for (e2 = 1; e2 < n; e2 <<= 1);
    nodes.assign(e2 * 2, defv);
  }

  T &geti(int i) { return nodes[e2 - 1 + i]; }
  void seti(int i, T v) { geti(i) = v; }

  void setall() {
    for (int j = e2 - 2; j >= 0; j--)
      nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2];
  }

  void set(int i, T v) {
    int j = e2 - 1 + i;
    nodes[j] = v;
    while (j > 0) {
      j = (j - 1) / 2;
      nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2];
    }
  }

  T sum_range(int r0, int r1, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return defv;
    if (r0 <= i0 && i1 <= r1) return nodes[k];

    int im = (i0 + i1) / 2;
    T v0 = sum_range(r0, r1, k * 2 + 1, i0, im);
    T v1 = sum_range(r0, r1, k * 2 + 2, im, i1);
    return v0 + v1;
  }
  T sum_range(int r0, int r1) { return sum_range(r0, r1, 0, 0, e2); }
};

/* global variables */

int as[MAX_N];
SegTreeSum<Elm> st;

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  sort(as, as + n);

  st.init(n, Elm(INF));
  for (int i = 0; i < n; i++) st.seti(i, Elm(as[i]));
  st.setall();

  double maxr = 0.0;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) {
      if (i + 1 == j) {
	Elm e0 = st.sum_range(0, i);
	Elm e1 = st.sum_range(j + 1, n);
	int x0 = (i > 0) ? as[i - 1] : -INF;
	int x1 = (j + 1 < n) ? as[j + 1] : INF;
	int d = min(x1 - x0, min(e0.d, e1.d));
	maxr = max(maxr, (double)(as[i] + as[j]) / d);
	//printf("i=%d,j=%d -> d=%d\n", i, j, d);
      }
      else {
	Elm e0 = st.sum_range(0, i);
	Elm e1 = st.sum_range(i + 1, j);
	Elm e2 = st.sum_range(j + 1, n);
	int x0 = (i > 0) ? as[i - 1] : -INF;
	int x1 = as[i + 1];
	int x2 = as[j - 1];
	int x3 = (j + 1 < n) ? as[j + 1] : INF;
	int d = min(min(x1 - x0, x3 - x2), min(e0.d, min(e1.d, e2.d)));
	maxr = max(maxr, (double)(as[i] + as[j]) / d);
	//printf("i=%d,j=%d -> d=%d\n", i, j, d);
      }
    }

  printf("%.8lf\n", maxr);
  return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 3012
final_rank: 11

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
using ld = long double;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    for(auto &it: a) cin >> it;

    sort(a.begin(), a.end());
    vector<ld> res;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i == j) continue;
            int p, q;
            for(p = n-1; p >= 0; p--){
                if(p != i && p != j) break;
            }
            for(q = n-1; q >= 0; q--){
                if(q != p && q != i && q != j) break;
            }
            res.emplace_back((ld)(a[p]+a[q])/(a[i]-a[j]));
        }
    }
    sort(res.begin(), res.end());
    cout << fixed << setprecision(10) << res.back() << endl;
    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 21556
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int n; cin >> n;
    vector<ld> a(n); cin >> a;
    SORT(a);
    ld ans = 0;
    FOR(i, 0, n)FOR(j, 0, i) {
        vector<ld> b;
        for (int k = n - 1; b.size() < 2; --k) {
            if (k != i && k != j)b.push_back(a[k]);
        }
        chmax(ans, (b[0] + b[1]) / (a[i] - a[j]));
    }
    print(ans);

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3324
final_rank: 5

code_snippet: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    sort(v.begin(),v.end(), greater<>());
    double ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            for (int k = 0; k < 3; ++k) {
                for (int l = k+1; l < 4; ++l) {
                    if(i != k && i != l && j != k && j != l){
                        ans = max(ans, 1.0*(v[k]+v[l])/(v[i]-v[j]));
                    }
                }
            }
        }
    }
    printf("%.10lf\n", ans);
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3284
final_rank: 1

code_snippet: #include <bits/stdc++.h>

using namespace std;

int N;
int Data[1000];
multiset<int> Numbers;

int main() {
	double maxSum, minSub, ans;

	Numbers.clear();
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> Data[i];
		Numbers.insert(Data[i]);
	}

	ans = 0.0;
	for (int i = 0; i < N; ++i) {
		Numbers.erase(Numbers.find(Data[i]));
		for (int j = 0; j < N; ++j) {
			if (i == j) {
				continue;
			}
			Numbers.erase(Numbers.find(Data[j]));
			maxSum = *(Numbers.rbegin()) + *(++Numbers.rbegin());
			minSub = abs(Data[i] - Data[j]);
			ans = max(ans, maxSum / minSub);
			Numbers.insert(Data[j]);
		}
		Numbers.insert(Data[i]);
	}
	cout << fixed << setprecision(6) << ans << endl;

	return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 3280
final_rank: 12

code_snippet: #include "bits/stdc++.h"
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define inv(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define endl "\n"
#define Endl "\n"

using namespace std;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int x, unsigned int y) {                                                    //return x^y in order(log(y))
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}
template<class T>
void cumulative_sum(T &container) {
  for (int i = 0; i < container.size() - 1; i++) container[i + 1] += container[i];
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<double> a(N);
  rep(i, N) cin >> a[i];
  double ans = -INF;
  sort(ALL(a));
  vector<vector<double>> check(N * (N - 1) / 2, vector<double>(3));
  int now = 0;
  rep(i, N - 1) {
    FOR(j, i + 1, N) {
      check[now++] = {a[j] - a[i], a[i], a[j]};
    }
  }
  sort(ALL(check));
  rep(i, N - 1) {
    FOR(j, i + 1, N) {
      rep(k, check.size()) {
        if (a[i] != check[k][1] and a[i] != check[k][2] and a[j] != check[k][1] and a[j] != check[k][2]) {
          ans = max(ans, (a[i] + a[j]) / check[k][0]);
          break;
        }
      }
    }
  }
  cout << fixed << setprecision(10) << ans << endl;
}
accuracy: 1
time_ms: 290
memory_kb: 30244
final_rank: 20

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
using namespace std;

int main(){
    long long int n,z=0;
    double ans=0;
    cin>>n;
    vector<double>a(1000000);
    vector<double>b(1000000);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end(),greater<>());
    for(int i=0;i<n-1;i++){
        for(int j=0;j<n-1;j++){
            if(ans<(a[i]+a[i+1])/(a[j]-a[j+1])&&i!=j&&i+1!=j&&i!=j+1){
                ans=(a[i]+a[i+1])/(a[j]-a[j+1]);
            }
        }
    }
    cout<<fixed <<setprecision(6)<<ans<<endl;
   return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 18400
final_rank: 15

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set>
using namespace std;
//int p = 998244353;
int p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define rev(s) reverse(s.begin(),s.end())
int max_kai = 150000;
vel kai(max_kai, 1);
vel inv_kai;
int rui(int a, int n) {
	if (n == 0) { return 1; }
	int x = rui(a, n / 2);
	x *= x; x %= p;
	if (n % 2 == 1) { x *= a; x %= p; }
	return x;
}
int inv(int a) { return rui(a, p - 2); }
void make_kai() {
	for (int i = 1; i < max_kai; i++) { kai[i] = kai[i - 1] * i; kai[i] %= p; }
	inv_kai = kai;
	rep(i, max_kai) { inv_kai[i] = inv(kai[i]); }
}
int nCr(int n, int r) {
	int a = kai[n] * inv_kai[r]; a %= p;
	a *= inv_kai[n - r]; a %= p;
	return a;
}
int inf = 6000000000000;
vel dijk(vvel &way, vel &cost, int s) {
	int n = way.size(); int m = 7 * n;
	vel ans(m, inf);
	priority_queue<pin, vector<pin>, greater<pin>> que;//cost,pla
	que.push(mkp(0,s));
	while (!que.empty()) {
		pin x = que.top(); que.pop();
		int pla = x.second;
		if (ans[pla] == inf) {
			int sum_cost = x.first;
			ans[pla] = sum_cost;
			int nex_cost = sum_cost + cost[pla];
			int mod = nex_cost % 7;
			for (auto x : way[pla/7]) {
				que.push(mkp(nex_cost, x * 7 + mod));
			}
		}
	}
	return ans;
}
vel pa;
int root(int x) {
	if (pa[x] == -1) { return x; }
	int ans = root(pa[x]); pa[x] = ans;
	return ans;
}
void marge(int x, int y) {
	x = root(x);
	y = root(y);
	if (x != y) {pa[x] = y;}
}
#define lower(h,val) lower_bound(h.begin(),h.end(),val)-h.begin()
#define upper(h,val) upper_bound(h.begin(),h.end(),val)-h.begin()
int sol(int a, int b, int c, int d) {
	return abs(a*c - b * d);
}
signed main(){
	int n; cin >> n;
	V<double> a(n);
	rep(i, n) { cin >> a[i]; }
	sor(a);
	double ans=0;
	rep(i, n) {
		rep(j, i) {
			vel ex;
			for (int k = n-1; k >= n-4; k--) {
				if (k != i && k != j) {
					ex.push_back(k);
				}
			}
			mmax(ans, (a[ex[0]] + a[ex[1]]) / (a[i] - a[j]) );
		}
	}
	printf("%.6lf\n", ans);
	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 4304
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long double ld;

int main() {
    int N;
    cin >> N;
    ld a[N], ans = 0;
    for (auto &x : a) cin >> x;
    vector<pair<ld, int>> tmp;
    for (int i = 0; i < N; i++) {
        tmp.push_back(make_pair(a[i], i));
    }
    sort(tmp.begin(), tmp.end());
    vector<int> index;
    for (int i = N - 4; i < N; i++) {
        index.push_back(tmp[i].second);
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i == j) continue;
            ld C = a[i];
            ld D = a[j];
            vector<int> MAX;
            for (int k = 3; 0 <= k && MAX.size() != 2; k--) {
                if (index[k] != i && index[k] != j) {
                    MAX.push_back(index[k]);
                }
            }
            ans = max(ans, (a[MAX[0]] + a[MAX[1]]) / (C - D));
        }
    }
    cout << fixed << setprecision(10) << ans << endl;
}
accuracy: 1
time_ms: 50
memory_kb: 3356
final_rank: 7

code_snippet: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int n; cin >> n;
	VI a(n); rep(i, n)cin >> a[i];
	sort(all(a));
	
	double ans = -(double)inf;
	rep(i, n) {
		FOR(j, i + 1, n) {
			int cd = a[j] - a[i];
			VI v_ab;
			for (int k = n - 1; k >= 0; --k) {
				if (k != i && k != j)v_ab.pb(a[k]);
				if (sz(v_ab) == 2)break;
			}
			int ab = v_ab[0] + v_ab[1];

			ans = max(ans, (double)ab / cd);
		}
	}
	printf("%.20f\n", ans);
}
accuracy: 1
time_ms: 20
memory_kb: 3244
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    multiset<int, greater<int>> s;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        s.insert(a[i]);
    }

    double ans = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = i + 1; j < n; ++j) {
            s.erase(a[i]);
            s.erase(a[j]);
            double x = abs(a[i] - a[j]);
            double y = *s.begin() + *(next(s.begin()));
            s.insert(a[i]);
            s.insert(a[j]);
            ans = max(ans, y / x);
        }
    }

    cout << fixed << setprecision(10) << ans << endl;
}
accuracy: 1
time_ms: 90
memory_kb: 3324
final_rank: 10

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

typedef pair<long long int, long long int> P;
typedef pair<long long int, P> Q;

bool ss(P a, P b) {
	if (a.first != b.first && a.first != b.second && a.second != b.first && a.second != b.second) {
		return true;
	}
	return false;
}

int main() {
	int n;
	cin >> n;
	vector<long long int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	vector<Q> b;
	vector<Q> c;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			b.push_back(Q(a[j]-a[i], P(a[i], a[j])));
			c.push_back(Q(a[j]+a[i], P(a[i], a[j])));
		}
	}
	double MAX = 0.0;
	int sz = b.size();
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	for (int i = 0; i < sz; i++) {
		if (ss(b[0].second, c[i].second)) {
			MAX = max(MAX, (double)c[i].first / (double)b[0].first);
		}
		if (ss(b[i].second, c[sz - 1].second)) {
			MAX = max(MAX, (double)c[sz-1].first / (double)b[i].first);
		}
	}
	printf("%.10f\n", MAX);
	return 0;
}
accuracy: 1
time_ms: 140
memory_kb: 26684
final_rank: 19

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;


main()
{
  int N;
  int data[1001];
  vector<Pip> v;

  cin >> N;
  Rep(i, N) cin >> data[i];

  for(int i=0; i<N-1; i++) {
    for(int j=i+1; j<N; j++) {
      v.pb( Pip( data[i] + data[j], Pii( i, j ) ) );
    }
  }

  sort( All( v ) );
  /*for(int i=0; i<v.size(); i++) {
    cout << v[i].fr << endl;
    }*/
  double mx = 0;
  for(int i=0; i<N; i++) {
    for(int j=0; j<N; j++) {
      if( i == j ) continue;
      if( data[i] - data[j] == 0 ) {
	continue;
      }
      else if( data[i] - data[j] > 0 ) {
	for(int k=v.size()-1; k>=0; k--) {
	  Pip p = v[k];
	  if( p.sc.fr == i || p.sc.fr == j || p.sc.sc == i || p.sc.sc == j ) continue;
	  else {
	    mx = max( mx, (double)((double)p.fr / (double)(data[i] - data[j])) );
	    break;
	  }
	}
      }     
    }
  }

  printf("%.7lf\n", mx);
}
accuracy: 1
time_ms: 50
memory_kb: 15152
final_rank: 16

code_snippet: #include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>

using namespace std;

double calFormula(const int64_t &A, const int64_t &B, const int64_t &C, const int64_t &D)
{
    return (double)(A+B) / (C-D);
}

int main()
{

    int N;
    cin >> N;

    vector<int64_t> list(N);
    for(int i = 0; i < N; i++)
    {
        cin >> list[i];
    }

    sort(list.begin(),list.end());
    reverse(list.begin(),list.end());

    double max_val = 0;
    //loop

    for(int a = 0; a < N; a++)
    {
        if(a > 10){ break; }
        for(int b = a + 1; b < N; b++)
        {
            if(b > 10){ break; }
            for(int c = 0; c < N; c++)
            {
                if(a == c || b == c){ continue; }
                for(int d = c + 1; d < N; d++)
                {
                    if(a == d || b == d){ continue; }
                    max_val = max(max_val, calFormula( list[a], list[b], list[c], list[d] ));
                }
            }
        }
    }


    cout << fixed << setprecision(5);
    cout << max_val << endl;

    return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 3284
final_rank: 9

code_snippet: #include<bits/stdc++.h>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-6)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

int n, a[1010];

int main() {
  cin >> n;
  rep(i,n) cin >> a[i];
  sort(a,a+n);
  double maxi = 0;
  rep(i,n) REP(j,i+1,n) {
    double C = a[j], D = a[i];
    double A,B;
    int k = n-1;
    vector<int> ps;
    while( ps.size() < 2 ) {
      assert( k >= 0 );
      if( k != i && k != j ) ps.push_back(k);
      --k;
    }
    A = a[ps[0]];
    B = a[ps[1]];
    maxi = max(maxi,(A+B)/(C-D));
  }
  printf("%.10f\n",maxi);
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3256
final_rank: 4

code_snippet: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n, a[10000], T[10000];
int main() {
	cin >> n; for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n);
	long double maxn = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			T[i] = 1; T[j] = 1;
			vector<int>vec;
			for (int k = n - 1; k >= 0; k--) {
				if (T[k] == 0)vec.push_back(a[k]);
				if (vec.size() == 2)break;
			}
			maxn = max(maxn, 1.0l*(vec[0] + vec[1]) / (a[j] - a[i]));
			T[i] = 0; T[j] = 0;
		}
	}
	printf("%.15Lf\n", maxn);
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3236
final_rank: 2