Problem:


Score : 400 points

Problem Statement

Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order.
From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized.
If there are multiple pairs that maximize the value, any of them is accepted.

Constraints

2 \leq n \leq 10^5

0 \leq a_i \leq 10^9

a_1,a_2,...,a_n are pairwise distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

n
a_1 a_2 ... a_n

Output

Print a_i and a_j that you selected, with a space in between.

Sample Input 1

5
6 9 4 2 11

Sample Output 1

11 6

\rm{comb}(a_i,a_j) for each possible selection is as follows:

\rm{comb}(4,2)=6 

\rm{comb}(6,2)=15 

\rm{comb}(6,4)=15 

\rm{comb}(9,2)=36 

\rm{comb}(9,4)=126 

\rm{comb}(9,6)=84 

\rm{comb}(11,2)=55 

\rm{comb}(11,4)=330 

\rm{comb}(11,6)=462 

\rm{comb}(11,9)=55

Thus, we should print 11 and 6.

Sample Input 2

2
100 0

Sample Output 2

100 0



Sample input:
5
6 9 4 2 11


Sample output:
11 6

Submission status: Time Limit Exceeded

Solution code:
from math import factorial as fact
from itertools import combinations as comb


def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    ans = [0,0]
    tmp = 0
    for i,j in comb(a,2):
        t = fact(max(i,j))//(fact(max(i,j)-min(i,j))*fact(min(i,j)))
        if tmp < t:
            ans = [max(i,j),min(i,j)]
            tmp = t
    print(ans[0],ans[1])


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math

def combination_count(n,r):
  return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

N=int(input())
a=list(map(int,input().split()))
maxoutput=0
output=0
n=0
r=0

a.sort(reverse=True)

for i in range(N):
  for j in range(i+1,N):
    output=combination_count(a[i],a[j])
    if output>maxoutput:
      maxoutput=output
      n=a[i]
      r=a[j]
    else:
      break;
print(n,r)

Submission status: Time Limit Exceeded

Solution code:
import math

def combination_count(n,r):
  return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

N=int(input())
a=list(map(int,input().split()))
maxoutput=0
output=0
n=0
r=0

a.sort(reverse=True)

for i in range(N):
  for j in range(i+1,N):
    output=combination_count(a[i],a[j])
    if output>maxoutput:
      maxoutput=output
      n=a[i]
      r=a[j]
print(n,r)

Submission status: Time Limit Exceeded

Solution code:
import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
a = [int(x) for x in input().split()]

x = max(a)
maxc = 0
maxy = 0
for y in sorted(a):
    if x == y or y < x // 2:
        continue
    c = comb(x, y)
    if maxc < c:
        maxc = c
        maxy = y

print(str(x) + ' ' + str(maxy))

Submission status: Time Limit Exceeded

Solution code:
import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
a = [int(x) for x in input().split()]

x = max(a)
maxc = 0
maxy = 0
for y in a:
    if x == y:
        continue
    if maxc < comb(x, y):
        maxc = comb(x, y)
        maxy = y

print(str(x) + ' ' + str(maxy))

Submission status: Time Limit Exceeded

Solution code:


cache = {0: 1, 1: 1, 2: 2}
combo_cache = {}


def prepare_cache():
    val = 1
    for i in range(1, 10000):
        val *= i
        cache[i] = val

def permutation(n):
    if n in cache:
        return cache[n]

    ret = n
    for i in range(n-1, 0, -1):
        if i in cache:
            ret *= cache[i]
            cache[n] = ret
            return ret

        ret *= i
    return ret


def combo(n, r):
    key = str(n) + "-" + str(r)
    if key in combo_cache:
        return combo_cache[key]

    x = permutation(n)
    y = permutation(n-r)
    z = permutation(r)
    combo_cache[key] = int(x // (y * z))
    return combo_cache[key]


count = int(input())
li = list(map(int, input().split()))
#
# data = open("input.txt", "r")
# l = data.read()
# li = list(map(int, l.split(" ")))

prepare_cache()

sli = sorted(li)

pair_a = 0
pair_b = 0
current_max = 0

i = sli[len(sli) - 1]

for j in range(0, len(sli) - 1):
    val = combo(i, sli[j])
    # print(str(sli[i]) + ", " + str(sli[j]) + ", " + str(val))
    if val > current_max:
        current_max = val
        pair_a = i
        pair_b = sli[j]

print(str(pair_a) + " " + str(pair_b))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = sorted(list(map(int, input().split())))

import numpy as np
from scipy.misc import comb

i = 0
j = N//2

ans = (0, 0)
x = 0
for j in range(1, N):
    n = a[j]
    while j - i > 1:
        if abs(n/2 - a[i]) < abs(n/2 - a[i+1]):
            break
        i+=1
    p = a[i]
    y = comb(n, p)
    if y > x:
        x = y
        ans = (n, p)

print(str(ans[0]), str(ans[1]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = sorted(list(map(int, input().split())))

import numpy as np
from scipy.misc import comb

i = 0
j = 1

ans = (0, 0)
x = 0
for j in range(1, N):
    n = a[j]
    while j - i > 1:
        if abs(n/2 - a[i]) < abs(n/2 - a[i+1]):
            break
        i+=1
    p = a[i]
    y = comb(n, p)
    if y > x:
        x = y
        ans = (n, p)

print(str(ans[0]), str(ans[1]))

Submission status: Time Limit Exceeded

Solution code:


cache = {0: 1, 1: 1, 2: 2}
combo_cache = {}


def permutation(n):
    if n in cache:
        return cache[n]

    ret = n
    for i in range(n-1, 0, -1):
        if i in cache:
            ret *= cache[i]
            cache[n] = ret
            return ret

        ret *= i
    return ret


def combo(n, r):
    key = str(n) + "-" + str(r)
    if key in combo_cache:
        return combo_cache[key]

    x = permutation(n)
    y = permutation(n-r)
    z = permutation(r)
    combo_cache[key] = int(x // (y * z))
    return combo_cache[key]


count = int(input())
li = list(map(int, input().split()))
#
# data = open("input.txt", "r")
# l = data.read()
# li = list(map(int, l.split(" ")))


sli = sorted(li)

pair_a = 0
pair_b = 0
current_max = 0

i = sli[len(sli) - 1]

for j in range(0, len(sli) - 1):
    val = combo(i, sli[j])
    # print(str(sli[i]) + ", " + str(sli[j]) + ", " + str(val))
    if val > current_max:
        current_max = val
        pair_a = i
        pair_b = sli[j]

print(str(pair_a) + " " + str(pair_b))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = sorted(list(map(int, input().split())))
import numpy as np
from scipy.misc import comb

def find_p(n, i):
    lo = 0
    hi = i
    mid = (hi-lo)//2
    xl = a[0]
    xh = a[i]
    while hi - lo > 1:
        mid = (hi+lo)//2
        if a[mid] > n//2:
            hi = mid
        else:
            lo = mid
    if abs(a[lo] - n/2) > abs(a[hi] - n/2):
        return a[hi]
    else:
        return a[lo]

ans = (0, 0)
x = 0
for j in range(N):
    i = N-j-1
    if a[i] < ans[1]:
        break
    n = a[i]
    p = find_p(n, i)
    y = comb(n, p)
    if y > x:
        ans = (n, p)
        x = y

print(str(ans[0]) + ' ' + str(ans[1]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = sorted(list(map(int, input().split())))
import numpy as np
from scipy.misc import comb

def find_p(n, i):
    lo = 0
    hi = i
    mid = (hi-lo)//2
    xl = a[0]
    xh = a[i]
    while hi - lo > 1:
        mid = (hi+lo)//2
        if a[mid] > n//2:
            hi = mid
        else:
            lo = mid
    if abs(a[lo] - n/2) > abs(a[hi] - n/2):
        return a[hi]
    else:
        return a[lo]

ans = (0, 0)
x = 0
for j in range(N):
    i = N-j-1
    n = a[i]
    p = find_p(n, i)
    y = comb(n, p)
    if y > x:
        ans = (n, p)
        x = y

print(str(ans[0]) + ' ' + str(ans[1]))

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())
l0 = list(map(int, input().split()))
mini = max(l0) + 1
maxii = 0
for i in l0:
    if i != max(l0) and (abs(max(l0)/2 - i)) < mini:
        mini = max(l0)/2 - i
        maxii = i

print(max(l0), maxii)

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())
l0 = list(map(int, input().split()))
mini = math.factorial(max(l0))
maxii = 0
for i in l0:
    if i != max(l0) and math.factorial(max(l0)-i)*math.factorial(i) < mini:
        mini = math.factorial(max(l0)-i)*math.factorial(i)
        maxii = i

print(max(l0), maxii)

Submission status: Time Limit Exceeded

Solution code:
import math


def k_choose_r(k,r):
    return math.factorial(k) / math.factorial(r) / math.factorial(k-r)


n = int(raw_input())
nums = map(int, raw_input().split())

nums = sorted(nums)
top = nums[-1]
best_value = 0
low = nums[n / 2 - 1]
high = nums[n / 2]

low_val = k_choose_r(top, low)
high_val = k_choose_r(top, high)

if low_val > high_val:
    bottom = low
else:
    bottom = high

if bottom == top:
    bottom = low + high - bottom

print "{} {}".format(top, bottom)

Submission status: Time Limit Exceeded

Solution code:
import math


def n_choose_r(n,r):
    return math.factorial(n) / math.factorial(r) / math.factorial(n-r)


n = int(raw_input())
nums = map(int, raw_input().split())

top = max(nums)
best_value = 0
for x in nums:
    if x == top:
        continue
        
    val = n_choose_r(top, x)
    if val > best_value:
        best_value = val
        bottom = x

print "{} {}".format(top, bottom)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
inline = list(map(int,input().split()))
inline.sort()

n = inline[-1]
kouho = int(n/2)

key = 0
i=0
r = 0
while key<1:

    if kouho +i in inline and kouho+i != n:
        key += 1
        r = kouho+i
    elif kouho -i in inline:
        key += 1
        r = kouho-i
    i+=1

print(n,end = " ")
print(r)

Submission status: Accepted

Solution code:
n = int(input())
a_list = list(map(int, input().split()))

a_list_min = sorted(a_list)
ai = a_list_min[-1]

mid_ai = ai // 2

for i in range(n):
    if a_list_min[i] >= mid_ai:
        if i == 0:
            aj = a_list_min[i]
        elif i == n-1:
            aj = a_list_min[i-1]
        else:
            if a_list_min[i] - mid_ai > mid_ai - a_list_min[i-1]:
                aj = a_list_min[i-1]
            else:
                aj = a_list_min[i]
        break
print(ai, aj)

Submission status: Accepted

Solution code:
n = int(input())
a = set(map(int, input().split()))

n, r = max(a), -pow(10, 9)
a.remove(n)
for ai in a:
    if abs(n // 2 - r) > abs(n // 2 - ai):
        r = ai
print(n, r)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))

n, r = max(a), -pow(10, 9)
for ai in a:
    if abs(n // 2 - r) > abs(n // 2 - ai) and ai != n:
        r = ai
print(n, r)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))

n, cnt, r = max(a), max(a) // 2, -pow(10, 9)
for ai in a:
    if abs(cnt - r) > abs(cnt - ai) and ai != n:
        r = ai
print(n, r)

Submission status: Accepted

Solution code:
n = int(input())
Alist = list(map(int,input().split()))
Alist.sort()
n = Alist[-1]
if n%2 == 0:
    R = n//2
    r = Alist[0]
    rmin = 10**9
    for i in Alist:
        if abs(i-R) < rmin:
            r = i
            rmin = abs(r-R)
else:
    R1 = (1+n)//2
    R2 = (n-1)//2
    r = Alist[0]
    rmin = 10**9
    for i in Alist:
        if abs(i-R1) < rmin or abs(i-R2) < rmin:
            r = i
            rmin = min(abs(r-R1),abs(r-R2))
print(n,r)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
comba = max(a)
ref = 10**10

for i in a:
    temp = abs(i - comba/2)
    if ref > temp:
        if comba > i:
            ref = temp
            combb = i

print(comba, combb)

Submission status: Accepted

Solution code:
from bisect import *

N = int(input())
A = list(map(int, input().split()))
A.sort()
i = bisect_left(A,A[-1]/2)
if A[i] - A[-1]/2 < A[-1]/2 - A[i-1]:
    a = A[i]
else:
    a = A[i-1]
print(A[-1], a)

Submission status: Accepted

Solution code:
import math
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
di = ls[:]
di.append(ls[-1]//2)
di.sort()
ind = di.index(ls[-1]//2)
il,ir = -1,-1
if ind > 0:
    il = ind - 1 
if ind < n-1:
    ir = ind + 1
if il < 0 or ir < 0:
    now = max(ir,il)
else:
    if ls[-1] % 2 == 0:
        if abs(ls[-1]//2 - di[ir]) < abs(ls[-1]//2 - di[il]):
            now = di[ir]
        else:
            now = di[il]
    else:
        if min(abs(ls[-1]//2 - di[ir]),abs(ls[-1]//2 + 1 - di[ir])) < min(abs(ls[-1]//2 - di[il]),abs(ls[-1]//2 + 1 - di[il])):
            now = di[ir]
        else:
            now = di[il]
print(ls[-1],now)

Submission status: Accepted

Solution code:
import bisect
n=int(input())
a=[int(x) for x in input().split()]
a.sort()

ma=max(a)
mi=float('inf')
ans=0
for i in range(n-1):
  sa=ma-a[i]
  if abs(a[i]-sa)<=mi:
    mi=abs(a[i]-sa)
    ans=a[i]

print(ma,ans)

Submission status: Accepted

Solution code:
import bisect
n=int(input())
a=[int(x) for x in input().split()]
a.sort()

ma=max(a)
half=ma//2
mi=float('inf')
for i in range(n):
  if abs(half-a[i])<=abs((half-mi)) and ma!=a[i]:
    mi=a[i]

print(ma,mi)

Submission status: Accepted

Solution code:
n = input()
l = list(map(int, input().split()))
m = max(l)
if n == '2':
    print(m,min(l))
else:
    r = min(l, key = lambda x: abs(x-(m//2)))
    print(m,r)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    
    N = int(input())
    A = set(map(int,input().split()))
    A = sorted(list(A))

    import bisect

    ans = A[-1]/2
    b = bisect.bisect_left(A,ans)

    if abs(ans-A[b])<abs(ans-A[max(0,b-1)]):
        print(A[-1],A[b])
    else:
        print(A[-1],A[b-1])

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
b=max(a)
c=[abs(b/2-i) for i in a[:-1]]
print(b,a[c.index(min(c))])

Submission status: Accepted

Solution code:
from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))

if n==2:
  print(str(max(a))+" "+str(min(a)))
  quit()

a.sort()
ans1=a.pop(n-1)
#print(a)
num = ans1//2
c = bisect_left(a, num)
cand1 = a[c]

if c!=0:
  cand2 = a[c-1]
  if abs(cand2-ans1/2)<abs(cand1-ans1/2):
    cand1=cand2
print(str(ans1)+" "+str(cand1))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import bisect
import math

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    n = II()
    a = LII()

    a.sort()
    n = a.pop(-1)
    mn = 10**9
    for ai in a:
        if abs(n//2 - ai) <= abs(n//2 - mn):
            mn = ai
    

    print(n, mn)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
one = max(a)
if one%2 == 0:
    test = one//2
else:
    test = one//2+1
x = float("inf")
diff = float("inf")
for i in a:
    if i < one:
        if abs(test-i) < diff:
            x = i
            diff = abs(test-i)
print(one,x)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()

max_val = a.pop()

max_dif = 10 ** 100
ret = 0

for item in a:
    dif = abs(max_val - item * 2)
    if max_dif > dif:
        ret = item
        max_dif = dif

print(max_val, ret)

Submission status: Accepted

Solution code:
n, *A = map(int, open(0).read().split())
A.sort()
a = A.pop()
b = min(A, key=lambda x: abs(x - a / 2))
print(a, b)

Submission status: Accepted

Solution code:
from bisect import *
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
ans = a[-1]/2
b = bisect_left(a,ans)
if abs(ans-a[b]) < abs(ans-a[b-1]):
  print(a[-1],a[b])
else:
  print(a[-1],a[b-1])

Submission status: Accepted

Solution code:
from bisect import *
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
ans = a[-1]//2
b = bisect_left(a,ans)
if a == [0,100]:
  print(100,0)
  exit()
if abs(ans-a[b]) <= abs(ans-a[b-1]):
  print(a[-1],a[b])
else:
  print(a[-1],a[b-1])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
a.sort()
mid = a[-1] / 2
ans = 10 ** 9
l = 0
for i in range(n):
    if ans > abs(mid - a[i]):
        ans = abs(mid - a[i])
        l = a[i]
print(a[-1], l)

Submission status: Accepted

Solution code:
#!python3

# input
n = int(input())
A = list(map(int, input().split()))


def main():
    W = sorted(A)
    a = W[-1]
    h = a / 2
    b = W[0]
    for x in W[1:-1]:
        if max(b - h, h - b) > max(x - h, h - x):
            b = x
    print(a, b)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))

A.sort()
# どの r を選んでも、n が大きいほうが大きい。
n = A[-1]
# n を固定したとき、n/2 に近いほうが大きい。
r = A[0]
for a in A[:-1]:
    if abs(n / 2  - a) < abs(n / 2 - r):
        r = a
print(n, r)

Submission status: Accepted

Solution code:
#最大値とその半分
#index不要

n= int(input())
a = list(map(int, input().split( )))
a.sort()
tmp = a[0]
for i in range(1,n-1):
    ##他参照
    if min(a[i],a[-1]-a[i])>min(tmp, a[-1]-a[i]):
        tmp = a[i]
print(a[-1],tmp)

Submission status: Accepted

Solution code:
N, = map(int, input().split())
As = list(map(int, input().split()))
am = max(As)
bm = (0,0)
for i, a in enumerate(As):
    if min(am-a, a) > min(bm):
        bm = (a, am-a)
print(am, bm[0])

Submission status: Accepted

Solution code:
import bisect
N = int(input())
A = list(map(int, input().split()))
A.sort()
ai = A[-1]

tmp = ai / 2
i = bisect.bisect_left(A, tmp)
if abs(tmp - A[i]) < abs(tmp - A[i - 1]):
    print(ai, A[i])
else:
    print(ai, A[i - 1])

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
N=max(a)
x=0
for i in a:
 if abs(N/2-i)<abs(N/2-x):
  x=i
print(N,x)

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
N=a[-1]
x=0
for i in a:
 if abs(N/2-i)<abs(N/2-x):
  x=i
print(N,x)

Submission status: Accepted

Solution code:
from bisect import *

n=int(input())
a=sorted(list(map(int,input().split())))
N=a[-1]
inx=bisect(a,N//2)
a=[a[0]]+a+[a[-1]]
th=10**9
for i in [a[inx-1],a[inx],a[inx+1]]:
 if abs(i-N//2)<=th and i<N:
  R=i
  th=abs(i-N//2)
print(N,R)

Submission status: Accepted

Solution code:
import numpy as np
import bisect
def getNearestValue(list_, num):
    idx = np.abs(np.asarray(list_) - num).argmin()
    return list_[idx]

N=int(input())
A=[int(i) for i in input().split()]

A.sort()
a=A[-1]
print(a,getNearestValue(A,a/2))

Submission status: Accepted

Solution code:
import bisect

n = int(input())
a = list(map(int, input().split()))
if n == 2:
    print(max(a), min(a))
    exit()

a.sort()
ans1 = a[-1]
tmp = ans1 // 2
index = bisect.bisect_left(a, tmp)
tmp1 = abs(tmp - a[index - 1])
tmp2 = abs(tmp - a[index])
if tmp1 < tmp2:
    ans2 = index - 1
else:
    ans2 = index

print(ans1, a[ans2])

Submission status: Accepted

Solution code:
import bisect as bi

n=int(input())
a=list(map(int,input().split()))
a.sort()
m=a[-1];a=a[:-1]

i=max(bi.bisect_left(a,m/2)-1,0)
j=min(i+1,n-2)

if m/2-a[i]<a[j]-m/2:
    r=a[i]
else:
    r=a[j]

print(m,r)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    max_a = max(a)
    ideal_comb = []
    if max_a % 2 == 0:
        ideal_comb.append(max_a // 2)
    else:
        ideal_comb.append(max_a // 2)
        ideal_comb.append(max_a // 2 + 1)

    diff = [0] * n

    for i in ideal_comb:
        for j in range(n):
            if a[j] == max_a:
                diff[j] += 10 ** 10
            else:
                diff[j] += abs(a[j] - i)

    tmp = diff.index(min(diff))

    print(max_a, a[tmp])

    


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from bisect import *

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    m = a[-1] / 2
    i = bisect(a, m)
    d0 = m - a[i - 1]
    d1 = a[i] - m
    if d0 < d1 or i == n - 1:
        print(a[-1], a[i - 1])
    else:
        print(a[-1], a[i])

main()

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
A.sort()

x=A.pop()
dif=0
ans=0
for i in range(n-1):
    a=A[i]
    tmp=min(a, x-a)
    if tmp>=dif:
        dif=tmp
        ans=a

print(x, ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007




n = I()
L = sorted(LI())
a = L[-1]
L = L[:-1]
l = bisect_left(L, a / 2)
if l < n - 1 and L[l] - a / 2 < a / 2 - L[l - 1]:
    print(a, L[l])
else:
    print(a, L[min(l - 1, n-2)])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
max_a = a[-1]
for i in range(len(a) - 1):
    if 2 * a[i] > max_a:
        half_ind = i
        break
    if i == (len(a) - 2):
        half_ind = n - 1

if half_ind == 0:
    print(str(a[-1]) + " " + str(a[half_ind]))
elif half_ind == n - 1:
    print(str(a[-1]) + " " + str(a[half_ind - 1]))
else:
    if abs(2 * a[half_ind] - a[-1]) > abs(2 * a[half_ind - 1] - a[-1]):
        print(str(a[-1]) + " " + str(a[half_ind - 1]))
    else:
        print(str(a[-1]) + " " + str(a[half_ind]))

Submission status: Accepted

Solution code:
# ARC095D - Binomial Coefficients (ABC094D)
def main():
    # pascal's triangle := mid area (nCn/2) is the biggest
    N = int(input())
    A = tuple(map(int, input().split()))
    n = max(A)
    mid, r, cur = n / 2, -1, float("inf")
    for i in A:
        if i != n:
            x = abs(mid - i)
            if x < cur:
                r, cur = i, x
    print(n, r)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import bisect


def solve(n: int, a: "List[int]"):
    a.sort()
    N = a[-1]
    i = bisect.bisect(a, N // 2)
    candidate = [a[i]]
    if i > 0:
        candidate.append(a[i-1])
    if i < n-1:
        candidate.append(a[i+1])
    m = N*2
    for c in candidate:
        if c == N:
            continue
        if abs(N//2 - c) < abs(N//2 - m):
            m = c
    print(N, m)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def find(A):
    A=sorted(A)
    MAX=A[-1]
    mid=MAX/2
    MIN=MAX
    need=-1
    for i in range(len(A)-1):
        if abs(A[i]-mid)<MIN:
            need=A[i]
            MIN=abs(A[i]-mid)
    return (MAX,need)
input()
x,y=find(list(map(int,input().strip().split(' '))))
print("{} {}".format(x,y))

Submission status: Accepted

Solution code:
import bisect

N = int(input())
A = list(map(int,input().split()))

A = sorted(A)

ans1 = A[-1]

ind = bisect.bisect_left(A, ans1/2)


c = float("inf")
for i in range(max(0,ind-1), min(N-1,ind+2)) :
    calc = abs(ans1/2 - A[i])
    if calc < c :
        ans2 = A[i]
        c = calc
print(ans1,ans2)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

maxa = max(a)

a.remove(maxa)

half = maxa / 2
minabs_from_half = 10**18

ans = -1
for ai in a:
    if abs(half - ai) < minabs_from_half:
        ans = ai
        minabs_from_half = abs(half - ai)

print(maxa, ans)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int, input().split()))
a1=max(A)
a2=0
for a in A:
    if abs(a1//2-a2)>abs(a1//2-a):
        a2=a
print(a1,a2)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))

x = max(a)

y = 0
for i in range(n):
    if abs(a[i]*2-x)<abs(y*2-x) and a[i]!=x:
        y = a[i]
print(x,end=' ')
print(y)

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
a.sort()
b=a.pop()
dif=float("inf")
ans=0
for i in range(n-1):
    if abs(a[i]-b/2)<dif:
        ans=a[i]
        dif=abs(a[i]-b/2)
print(b,ans)

Submission status: Accepted

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
A.sort()

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if len(A) == 2:
    print(A[1])
    print(A[0])

half = A[-1] / 2
for i in range(N-2):
    if abs(A[i]-half) >= abs(A[i+1]-half) <= abs(A[i+2]-half):
            print(A[-1])
            print(A[i+1])
            exit()

Submission status: Accepted

Solution code:
def getlist():
	return list(map(int, input().split()))

n = int(input())
a = getlist()
a = sorted(a)
x = a[-1]
xx = x / 2
y = 0
s = float("inf")
for i in range(n - 1):
	if abs(xx - a[i]) < s:
		s = abs(xx - a[i])
		y = a[i]

print(x, y)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()

maxi = a[-1]
mini = 1000000001
for i in range(n-1):
    if abs(maxi/2 - a[i]) < mini:
        minindex = i
        mini = abs(maxi/2 - a[i])
print(maxi, a[minindex])

Submission status: Accepted

Solution code:
import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = a[-1] / 2
i = bisect.bisect(a, b)
if a[i] - b < b - a[i - 1]:
    print(a[-1], a[i])
else:
    print(a[-1], a[i - 1])

Submission status: Accepted

Solution code:
def upperbound(zs, left, right, ok):
    if left + 1 >= right:
        return left
    m = (left + right) // 2
    if ok(zs[m]):
        return upperbound(zs, m, right, ok)
    else:
        return upperbound(zs, left, m, ok)

n = int(input())
xs = list(map(int, input().split()))

ds = sorted(xs)

a = ds[-1]
c = a / 2
zs = [d - c for d in ds[:-1]]

i = upperbound(zs, 0, len(zs)-1, lambda z: z<=0)

j = i+1 if i < len(zs)-1 else i

b = ds[i] if abs(zs[i]) < abs(zs[j]) else ds[j]

print(a, b)

Submission status: Accepted

Solution code:
n = int(input())
alist = list(sorted(map(int, input().split())))
maxa = alist[-1]
halfa = maxa / 2
mina = maxa
a2 = 0
for a in alist:
  if abs(halfa - a2) > abs(halfa - a):
    a2 = a
print(maxa, a2)

Submission status: Accepted

Solution code:
input();a=list(map(int,input().split()));m=max(a);b=[abs(2*i-m+0.1) for i in a];print(m,a[b.index(min(b))])

Submission status: Accepted

Solution code:
input()
a=list(map(int,input().split(' ')))
m=max(a)
a.remove(m)
b=[abs(2*i-m) for i in a]
print(m,a[b.index(min(b))])

Submission status: Accepted

Solution code:
input();a=list(map(int,input().split(' ')));m=max(a);a.remove(m);b=[abs(2*i-m) for i in a];print(m,a[b.index(min(b))])

Submission status: Accepted

Solution code:
import numpy as np;input();a=list(map(int,input().split(' ')));m=max(a);a.remove(m);b=[abs(2*i-m) for i in a];j=b.index(min(b));print(m,a[j])

Submission status: Accepted

Solution code:
from bisect import bisect_left
n = int(input())
a = sorted(list(map(int, input().split())))
r = bisect_left(a, a[-1]/2)
l = r-1 if r else 0
if abs(a[-1]/2 - a[l]) > abs(a[-1]/2 - a[r]):
    l,r = r,l
print(a[-1],a[l])

Submission status: Accepted

Solution code:
import bisect
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

n = int(input())
A = list(map(int, input().split()))

A = sorted(A)

ma = A[-1]
A = A[:-1]
mi = -1
mid = ma/2

mid_ind = bisect.bisect_left(A, mid)
l = n-1
if mid_ind >= l:
    mi = A[-1]
elif mid_ind <= 0:
    mi = A[0]
else:
    if abs(A[mid_ind]-mid) > abs(A[mid_ind-1]-mid):
        mi = A[mid_ind-1]
    else:
        mi = A[mid_ind]
print(ma, mi)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))

a.sort()
b = []
c = a[-1]/2
for i in range(n-1):
    b.append(abs(a[i]-c))

k = b.index(min(b))

print(a[-1],a[k])

Submission status: Accepted

Solution code:
N = int(input())
A = sorted([int(_) for _ in input().split()])


def comb(n, r):
    res = 1
    for i in range(n - r + 1, n + 1):
        res *= i
    for i in range(1, r):
        res //= i
    return res


x = A.pop()
N -= 1
for i in range(N):
    if A[i] > x // 2:
        break
if abs(A[i] - x / 2) < abs(A[i - 1] - x / 2):
    print(x, A[i])
else:
    print(x, A[i - 1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def main():

    n = input()
    a = sorted(list(map(int, input().split())))
    ai = max(a)
    a.remove(ai)
    aj = float('inf')
    tmp = float('inf')

    for aa in a:
        diff = abs(ai / 2 - aa)

        if diff < tmp:
            tmp = diff
            aj = aa

    print(ai, aj)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    ma = max(a)
    diff = 100000000000000
    ans = 0
    for aa in a:
        t = abs(ma//2-aa)
        if ma != aa and diff > t:
            diff = t
            ans = aa
    print(ma,ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
A.sort()
mid = A[-1]/2
Aj = A[0]
for i in range(1, N-1):
    if abs(A[i] - mid) < abs(Aj - mid):
        Aj = A[i]
print(A[-1], Aj)

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split()]

ai = max(a)
a.remove(ai) 
ans = 0
for aj in a:
    if min(ans,ai-ans) < min(aj,ai-aj):
        ans = aj
print(ai,ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = [int(x) for x in input().split()]

maxa = max(a)
mida = min(a)
for x in a:
    # print(x,mida,maxa//2-x)
    if abs(maxa//2 - x)<abs(maxa//2-mida):
        mida = x
print(maxa, mida)