Problem p03380 (C++)

Buggy submission (status: Runtime Error):
/*
vrrtll==???>;::::~~~~~~......`.`````````````````````...-?777!_.._?7u,~~~::::;>>??=lllttrrzu
rtll==??>>;::::~~~~......`.``````````````````
..J77!`````````...`..._T,~~~~:::;;>??==lttrrv
tll=??>>;:::~~~~......``````````````````..J7^ ` ``  ` ``
.,```````...._4,.~~~::;;>>?===lttr l=???>;;::~~~......`````HTSu,.``  `..J7!    `
`` .J"~N```````````..?&.~~~~::;;>>?==llt
=??>;;::~~~~.....``````.@????7SJ.?=     `     ` `` .J=....J;
``````````..h..~~~~::;;>??=ll
?>>;::~~~~.....````````.D?>>?>?>?8+.``         `.J"_......_b`
````````.S_.~~~~::;;>??=l
>;;::~~~~....``````````.C>??>>>?>>>?8J.`  ```..Y~..........J;  `  ` ```````
G...~~~~::;>??=
;;::~~~....```````` `..W1>>?>>>>?>>>>>?S,.`.7^.............-N``  `
``````` 6...~~~~::;>??
;:~~~~....``````` ..7` d??>>?>?>>?>>?>>1udMgggNNNNggJ.......([
`````.L...~~~~::;>?
:~~~.....`````` .7`   `K>?>?>>>>>>+ugNMMMB""7<!~~<?7TWMNNa,..w.`  ` `  `
`````,)....~~:::;>
~~~....``````.J^     ` #>>?>>>?jgMMM9=_................-?TMMa,b` `   `  `
````(,...~~~~:;;
~~~....``` .7``   `    @?>>?1uMM#=.........................(TMNa......  `
``````4....~~~::;
~~~...`` .=`` `     `
.b>>jgNH".................`.............?HNmx??17TYY9SA+(..L....~~~::
~....` ,^``     `   `
.b+dN#^............6..-(,-...`............(HMm+>>>>>?>>????zOM_.~~~::
.... .=```  `` `
...JNMM^..........`..._n.(MMN,....`..`.........?MNe<>>?>??>????d^...~~~:
~...v```` `
..-Z""!_..(M@_........`........?7MMMMp.................-TNN+?>>>????1d4-..-(Jk9
..(^`...zY"!_........(MD..............`......JMMMMp....`..`..`......./MNx>??>>?1d!.h7=~(??=
(v_`,R_.............(NF..(/..(&,...`..........?MMMM;..................(MMs>>?1&T"!``....(1=
t..``
4,...........(N@....?,(NMNR_.....`..`....(WMM$..`....`..`..`....._HMe7=```````....~_1
...````.4,........-dM:.....(7MMMNR-.....................`............(.?^ ``
``````....~~~
...``````,4,....`.(NF........(MMMMb..`....--................`....(.7!        `
````....~~:
..````` ` `.5J_...JMt.........?NMMM[...`.HH5._(J7[...`...`...--?^`          `
`````....~~~:
...````` `  ` 7a,.dM{....`...../MMMN......(J=`  .>......._(/=             `  `
`````...~~~:
....```` ``     (4MN{..........._7"^...(/^    `.C....-(J=`                  ` `
```....~~~:
....````` `      JdM[...`...`........`_3..  ..?!..(-7!                  ` `
``````....~~~:: r...``````  ` ``(CJMb..............`......__..-(?^ `  `
`````....~~::; J/...````` `  `,3>+MN-.`..`...`..........._(J=`` `  `
```````....~~~::; _j,..`.```` ``.5>>?dNb...`......`......_-?'` `
`````....~~~::;;
~~j,..```````.D??>>>MM/....`........(-=`                          `  ` `
```````...~~~:::;>
~~~j,...````.E??>??>?MN-.........(J=                            `   ` `
``````....~~~~::;??
:~~~?,...``.@>?>?>>??dMN_....-(?^                        `  `    ` `
````````...~~~~:;;>??
::~~~?/....K??????>>?>dMN-_(7!                               `  ` `
````````....~~~:::>>??l
;:::~~/e.(K==?????????<dM"!                          `    `   ` ` ``
``````...~~~~:::;>??=l
*/
#include "bits/stdc++.h"
using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, s, n) for (int i = (s); i < (n); ++i)
#define repr(i, n) for (int i = n - 1; i >= 0; --i)
#define REPR(i, s, n) for (int i = (s); i >= (n); --(i))
#define all(a) (a).begin(), (a).end()
#define reall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define pf push_front
#define MIN(a, b) a = min((a), (b))
#define MAX(a, b) a = max((a), (b))
#define SIZE(v) (int)v.size()
#define DOUBLE fixed << setprecision(15)
#define fi first
#define se second
const double pi = acos(-1.0);
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef vector<P> vP;
const ll mod = 1e9 + 7;
// const ll mod = 998244353;
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};
struct edge {
  int to;
  int cost;
};
void Pvll(vll v) {
  cout << "------------------------------------------------\n";
  rep(i, v.size()) cout << v[i] << " ";
  cout << endl;
  cout << "------------------------------------------------\n";
}
void Pvvll(vvll v) {
  cout << "------------------------------------------------\n";
  rep(i, v.size()) {
    rep(j, v[i].size()) { cout << v[i][j] << " "; }
    cout << endl;
  }
  cout << "------------------------------------------------\n";
}

void Ps(string s) {
  cout << "------------------------------------------------\n";
  rep(i, s.size()) cout << s[i] << " ";
  cout << endl;
  cout << "------------------------------------------------\n";
}

void Pvs(vs s) {
  cout << "------------------------------------------------\n";
  rep(i, s.size()) {
    rep(j, s[i].size()) { cout << s[i][j] << " "; }
    cout << endl;
  }
  cout << "------------------------------------------------\n";
}

void Yes(bool x) {
  if (x)
    cout << "Yes\n";
  else
    cout << "No\n";
}

void YES(bool x) {
  if (x)
    cout << "YES\n";
  else
    cout << "NO\n";
}

void yes(bool x) {
  if (x)
    cout << "yes\n";
  else
    cout << "no\n";
}

void Yay(bool x) {
  if (x)
    cout << "Yay!\n";
  else
    cout << ":(\n";
}

ll n, d, r, l, k, h, ans = 0, ret = M;
bool flag = false, flag2 = false, flag3 = false;
string s, t, u;

void INIT() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << DOUBLE;
}
#define MAX_N 200005
ll factorial[MAX_N];
void make_factorial_table() {
  factorial[0] = 1;
  for (int i = 1; i < MAX_N; i++) {
    factorial[i] = factorial[i - 1] * i % mod;
  }
}

ll bisection_power(ll x, ll y) {
  if (y == 0) {
    return 1;
  }
  ll t = bisection_power(x * x % mod, y / 2);
  if (y % 2 == 1) {
    t = t * x % mod;
  }
  return t;
}

ll nCr(int n, int r) {
  if (n < r || n <= 0 || r < 0) {
    return 0;
  }
  ll a = factorial[n];
  ll b = a * bisection_power(factorial[r], (mod - 2)) % mod;
  ll c = b * bisection_power(factorial[n - r], mod - 2) % mod;
  return c % mod;
}

int main() {
  INIT();
  // init
  make_factorial_table();

  cin >> n;
  vll v(n);
  rep(i, n) cin >> v[i];
  sort(all(v));
  if (n % 2) {
    if (nCr(v[v.size() - 1], v[n / 2 - 1]) > nCr(v[v.size() - 1], v[n / 2])) {
      cout << v[v.size() - 1] << " " << v[n / 2 - 1] << endl;
    } else
      cout << v[v.size() - 1] << " " << v[n / 2] << endl;
  } else
    cout << v[v.size() - 1] << " " << v[n / 2 - 1] << endl;
  return 0;
}

Fixed submission:
/*
vrrtll==???>;::::~~~~~~......`.`````````````````````...-?777!_.._?7u,~~~::::;>>??=lllttrrzu
rtll==??>>;::::~~~~......`.``````````````````
..J77!`````````...`..._T,~~~~:::;;>??==lttrrv
tll=??>>;:::~~~~......``````````````````..J7^ ` ``  ` ``
.,```````...._4,.~~~::;;>>?===lttr l=???>;;::~~~......`````HTSu,.``  `..J7!    `
`` .J"~N```````````..?&.~~~~::;;>>?==llt
=??>;;::~~~~.....``````.@????7SJ.?=     `     ` `` .J=....J;
``````````..h..~~~~::;;>??=ll
?>>;::~~~~.....````````.D?>>?>?>?8+.``         `.J"_......_b`
````````.S_.~~~~::;;>??=l
>;;::~~~~....``````````.C>??>>>?>>>?8J.`  ```..Y~..........J;  `  ` ```````
G...~~~~::;>??=
;;::~~~....```````` `..W1>>?>>>>?>>>>>?S,.`.7^.............-N``  `
``````` 6...~~~~::;>??
;:~~~~....``````` ..7` d??>>?>?>>?>>?>>1udMgggNNNNggJ.......([
`````.L...~~~~::;>?
:~~~.....`````` .7`   `K>?>?>>>>>>+ugNMMMB""7<!~~<?7TWMNNa,..w.`  ` `  `
`````,)....~~:::;>
~~~....``````.J^     ` #>>?>>>?jgMMM9=_................-?TMMa,b` `   `  `
````(,...~~~~:;;
~~~....``` .7``   `    @?>>?1uMM#=.........................(TMNa......  `
``````4....~~~::;
~~~...`` .=`` `     `
.b>>jgNH".................`.............?HNmx??17TYY9SA+(..L....~~~::
~....` ,^``     `   `
.b+dN#^............6..-(,-...`............(HMm+>>>>>?>>????zOM_.~~~::
.... .=```  `` `
...JNMM^..........`..._n.(MMN,....`..`.........?MNe<>>?>??>????d^...~~~:
~...v```` `
..-Z""!_..(M@_........`........?7MMMMp.................-TNN+?>>>????1d4-..-(Jk9
..(^`...zY"!_........(MD..............`......JMMMMp....`..`..`......./MNx>??>>?1d!.h7=~(??=
(v_`,R_.............(NF..(/..(&,...`..........?MMMM;..................(MMs>>?1&T"!``....(1=
t..``
4,...........(N@....?,(NMNR_.....`..`....(WMM$..`....`..`..`....._HMe7=```````....~_1
...````.4,........-dM:.....(7MMMNR-.....................`............(.?^ ``
``````....~~~
...``````,4,....`.(NF........(MMMMb..`....--................`....(.7!        `
````....~~:
..````` ` `.5J_...JMt.........?NMMM[...`.HH5._(J7[...`...`...--?^`          `
`````....~~~:
...````` `  ` 7a,.dM{....`...../MMMN......(J=`  .>......._(/=             `  `
`````...~~~:
....```` ``     (4MN{..........._7"^...(/^    `.C....-(J=`                  ` `
```....~~~:
....````` `      JdM[...`...`........`_3..  ..?!..(-7!                  ` `
``````....~~~:: r...``````  ` ``(CJMb..............`......__..-(?^ `  `
`````....~~::; J/...````` `  `,3>+MN-.`..`...`..........._(J=`` `  `
```````....~~~::; _j,..`.```` ``.5>>?dNb...`......`......_-?'` `
`````....~~~::;;
~~j,..```````.D??>>>MM/....`........(-=`                          `  ` `
```````...~~~:::;>
~~~j,...````.E??>??>?MN-.........(J=                            `   ` `
``````....~~~~::;??
:~~~?,...``.@>?>?>>??dMN_....-(?^                        `  `    ` `
````````...~~~~:;;>??
::~~~?/....K??????>>?>dMN-_(7!                               `  ` `
````````....~~~:::>>??l
;:::~~/e.(K==?????????<dM"!                          `    `   ` ` ``
``````...~~~~:::;>??=l
*/
#include "bits/stdc++.h"
using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, s, n) for (int i = (s); i < (n); ++i)
#define repr(i, n) for (int i = n - 1; i >= 0; --i)
#define REPR(i, s, n) for (int i = (s); i >= (n); --(i))
#define all(a) (a).begin(), (a).end()
#define reall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define pf push_front
#define MIN(a, b) a = min((a), (b))
#define MAX(a, b) a = max((a), (b))
#define SIZE(v) (int)v.size()
#define DOUBLE fixed << setprecision(15)
#define fi first
#define se second
const double pi = acos(-1.0);
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef vector<P> vP;
const ll mod = 1e9 + 7;
// const ll mod = 998244353;
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};
struct edge {
  int to;
  int cost;
};
void Pvll(vll v) {
  cout << "------------------------------------------------\n";
  rep(i, v.size()) cout << v[i] << " ";
  cout << endl;
  cout << "------------------------------------------------\n";
}
void Pvvll(vvll v) {
  cout << "------------------------------------------------\n";
  rep(i, v.size()) {
    rep(j, v[i].size()) { cout << v[i][j] << " "; }
    cout << endl;
  }
  cout << "------------------------------------------------\n";
}

void Ps(string s) {
  cout << "------------------------------------------------\n";
  rep(i, s.size()) cout << s[i] << " ";
  cout << endl;
  cout << "------------------------------------------------\n";
}

void Pvs(vs s) {
  cout << "------------------------------------------------\n";
  rep(i, s.size()) {
    rep(j, s[i].size()) { cout << s[i][j] << " "; }
    cout << endl;
  }
  cout << "------------------------------------------------\n";
}

void Yes(bool x) {
  if (x)
    cout << "Yes\n";
  else
    cout << "No\n";
}

void YES(bool x) {
  if (x)
    cout << "YES\n";
  else
    cout << "NO\n";
}

void yes(bool x) {
  if (x)
    cout << "yes\n";
  else
    cout << "no\n";
}

void Yay(bool x) {
  if (x)
    cout << "Yay!\n";
  else
    cout << ":(\n";
}

ll n, d, r, l, k, h, ans = 0, ret = M;
bool flag = false, flag2 = false, flag3 = false;
string s, t, u;

void INIT() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << DOUBLE;
}
#define MAX_N 200005
ll factorial[MAX_N];
void make_factorial_table() {
  factorial[0] = 1;
  for (int i = 1; i < MAX_N; i++) {
    factorial[i] = factorial[i - 1] * i % mod;
  }
}

ll bisection_power(ll x, ll y) {
  if (y == 0) {
    return 1;
  }
  ll t = bisection_power(x * x % mod, y / 2);
  if (y % 2 == 1) {
    t = t * x % mod;
  }
  return t;
}

ll nCr(int n, int r) {
  if (n < r || n <= 0 || r < 0) {
    return 0;
  }
  ll a = factorial[n];
  ll b = a * bisection_power(factorial[r], (mod - 2)) % mod;
  ll c = b * bisection_power(factorial[n - r], mod - 2) % mod;
  return c % mod;
}

int main() {
  INIT();
  // init
  make_factorial_table();

  cin >> n;
  vll v(n);
  rep(i, n) cin >> v[i];
  sort(all(v));
  // Pvll(v);
  ll ans = M, ansx = 0, ansy = 0;
  double x = v[v.size() - 1] * 1.000 / 2;
  rep(i, n - 1) {
    // cout << x << " " << ans << " " << ansy << endl;
    if (abs(x - v[i]) < ans) {
      ansy = i;
      ans = abs(x - v[i]);
    }
  }
  cout << v[v.size() - 1] << " " << v[ansy] << endl;
  return 0;
}