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: Accepted

Solution code:
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
m = A[-1]
i = bisect.bisect_left(A, m/2)
if i == 0:
  print(m, A[0])
  exit()
if i == N-1:
  print(m, A[-2])
  exit()
a, b = A[i-1], A[i]
if abs(a*2-m) > abs(b*2-m):
  print(m, b)
else:
  print(m, a)

Submission status: Accepted

Solution code:
import bisect

def main():
    n=int(input())
    a=sorted(map(int,input().split()))
    if len(a) < 3:
        print(a[1], a[0])
        return
    N = a[-1]
    a = a[:-1]
    r = bisect.bisect(a, N/2)
    if r == 0:
        R = a[0]
    if r == len(a):
        R = a[r-1]
    else:
        R = a[r] if abs(a[r-1] - N/2) > abs(a[r] - N/2) else a[r-1]
    print(N, R)
        
if __name__ == "__main__":
    main()

Submission status: Accepted

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

num = a[0]
tmp = a[1]
for j in range(1, n):
  if abs(tmp-num/2) >= abs(a[j]-num/2):
    tmp = a[j]
  else:
    break
ans = [num, tmp]
print(*ans)

Submission status: Accepted

Solution code:
import math
import numpy as np

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

n = int(input())
a = [int(i) for i in input().split()]
check = 0
a.sort()
b = a[-1]
c = getNearestValue(a,b/2)
ans = str(b) + ' ' + str(c)
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
As.sort()

from bisect import bisect_right
maxA = As[-1]
idx = bisect_right(As, maxA/2)

if abs(As[idx]-(maxA/2))>=abs(As[idx-1]-(maxA/2)):
    print(maxA, As[idx-1])
else:
    print(maxA, As[idx])

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
MaxA = max(A)
A = sorted(A,key=lambda x: abs(MaxA/2-x))
if A[0] == MaxA:
  print(MaxA,A[1])
else:
  print(MaxA,A[0])

Submission status: Accepted

Solution code:
import numpy as np

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

a.sort()


def get_nearest_value(arr, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(arr) - num).argmin()

    return arr[idx]


first = a[-1]
second = get_nearest_value(a, first / 2)

print(first, second)

Submission status: Accepted

Solution code:
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    mdl = a[0]//2
    if a[0]%2 == 0:
        dist = [abs(x-mdl) for x in a[1:]]
    else:
        dist = [abs(x-mdl) if x <= mdl else abs(x - mdl - 1) for x in a[1:]]
    idx = min(range(1,n), key=lambda i: dist[i-1])
    print(a[0], a[idx])
    
        
    
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

t2 = a[0]
x = a[0]//2
ans = 1
for i in range(1,n):
  t = abs(x - a[i])
  if t < t2:
    t2 = t
    ans = i
print(a[0],a[ans])

Submission status: Accepted

Solution code:
n, *A = map(int, open(0).read().split())
A.sort()
print(A[-1], min(A, key=lambda x:abs(2*x-A[-1])))

Submission status: Accepted

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

x = max(a)
m = x/2
a.remove(x)
a.sort()
ans = x

for i in a:
    y = abs(i - m)
    if ans >= y:
        ans = y
    else:
        break    
    z = i
      
print(x, z)

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
#print(a)
h=a[0]/2
dif=10**18
tmp=None
for i in range(1,n):
    if dif>abs(a[i]-h):
        dif=abs(a[i]-h)
        tmp=a[i]
print(a[0],tmp)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
aas = list(map(int, input().split()))
aas.sort()
l = aas[-1]
a = l // 2
b = l // 2 + 1
idx_a = bisect.bisect_left(aas,a)
idx_b = bisect.bisect_left(aas,a)
res = []
if aas[idx_a] != l:
    res.append(idx_a)
if aas[idx_b] != l:
    res.append(idx_b)
if idx_a > 0:
    if aas[idx_a-1] != l:
        res.append(idx_a-1)
if idx_b > 0:
    if aas[idx_b-1] != l:
        res.append(idx_b-1)
if idx_a < n - 1:
    if aas[idx_a+1] != l:
        res.append(idx_a+1)
if idx_b < n - 1:
    if aas[idx_b+1] != l:
        res.append(idx_b+1)
best = l // 2
res_f = n - 1
for i in set(res):
    if abs(best-aas[i]) <= abs(best-aas[res_f]):
        res_f = i
    if l%2 != 0:
        if abs(best+1 - aas[i]) <= abs(best+1 - aas[res_f]):
            res_f = i
print(str(l)+" "+str(aas[res_f]))

Submission status: Accepted

Solution code:
N = int(input())

a = list(map(int,input().split()))

a_max = max(a)

half_a = a_max//2

comb = 1000000000
for i in range(N):
    if a[i]==a_max:
        continue
    if comb>abs(half_a-a[i]):
        idx =i
        comb = abs(half_a-a[i])

print(str(a_max) + ' ' + str(a[idx]))

Submission status: Accepted

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

a.sort()
k = a[n-1]
r = a[0]
dis = abs(a[n-1]/2-a[0])
for i in range(n-1):
    if dis > abs(a[n-1]/2-a[i]):
        dis = abs(a[n-1]/2-a[i])
        r = a[i]
print(k,r)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


def solve():
    # n, m = [int(x) for x in input().split()]
    n = int(input())
    a = [int(x) for x in input().split()]
    a.sort()
    x = a[-1]
    y = a[0]
    t = x
    d = float('inf')
    for e in a:
        if abs(t - (x - e) * 2) < d:
            y = e
            d = abs(t - (x - e) * 2)
    print(x, y)
        

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""
a b a
d c d
a b a
"""

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    A.sort()
    ans = [str((m := A.pop())), ]
    m /= 2
    A = [(a, abs(a - m)) for a in A]
    A.sort(key = lambda x: x[1])
    ans.append(str(A[0][0]))
    print(' '.join(ans))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

A = sorted(A)
B = A[::]
n = A[-1]
temp = n // 2
min_ = 10 ** 9 + 7
for i in range(N - 1):
    A[i] -= temp
    A[i] = abs(A[i])
min_ = min(A)
for i in range(N - 1):
    if A[i] == min_:
        ans = B[i]
print(n, ans)

Submission status: Accepted

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

import math
import bisect
max = L[-1]
maxdiv2 = max//2
posleft = bisect.bisect_left(L, maxdiv2)
posright = bisect.bisect_right(L, maxdiv2)

if len(L) == 2:
	print(L[1], L[0])
	exit()

if posleft!= posright:
	print(max, L[posleft])
	exit()

if abs(max/2 - L[posleft]) > abs(max/2 - L[posleft-1]):
	print(max, L[posleft-1])
else:
	print(max, L[posleft])

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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

x = max(A)
A = list(filter(lambda a: a != x, A))
med = x / 2

num = INF
y = 0
for a in A:
    if abs(med - a) < num:
        num = abs(med - a)
        y = a
print(x, y)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

n = int(input())
a = LI()

"""
nCr = n!/(r! * (n-r)!)
なのでnは最大値をとりつつrはnの中間の値を撮るのが良さそう．
"""

a.sort()
o = a[-1]
diff = mod
for i in range(n):
    if diff > abs(a[i] - o / 2):
        p = a[i]
        diff = abs(a[i] - o / 2)
print(o,p)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
num1=a[-1]
num2=a[-1]/2
num3=a[-1]
ans=-1
for i in range(n-1):
    if abs(a[i]-num2)<num3:
        ans=a[i]
        num3=abs(a[i]-num2)
print(num1,ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
from bisect import bisect_left, bisect_right

def solve():
    N = II()
    A = LI()
    A = sorted(A)

    a = A[-1]
    mid = a / 2
    diff = INF
    b = -1
    for j in A[:-1]:
        d = abs(j - mid)
        if d < diff:
            b = j
            diff = d
    print(a, b)



if __name__ == '__main__':
    solve()

Submission status: Accepted

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

a.sort()
m = a[-1]
br = m/2
tmp = m
for i in range(n):
    if tmp > abs(a[i]-br):
        r = a[i]
        tmp = abs(a[i]-br)

print(m,r)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 998244353


def resolve():
    n = int(input())
    A = sorted(list(map(int, input().split())))

    MAX_V = A[-1]
    target = MAX_V // 2 if MAX_V % 2 == 0 else (MAX_V + 1) // 2

    diff = f_inf
    res = A[0]
    for i in range(n - 1):
        if abs(target - A[i]) < diff:
            diff = abs(target - A[i])
            res = A[i]
    print(MAX_V, res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

als =list(sorted(al))
m = als[n-1]

import bisect
x = bisect.bisect(als,m/2)

if abs(m/2 - als[x-1]) > abs(m/2 - als[x]):
    print(m,als[x])
else:
    print(m,als[x-1])

Submission status: Accepted

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

import bisect
import numpy as np
amax = a[-1]
cent = amax // 2

idx = bisect.bisect_left(a, cent)
if idx == len(a)-1:
    print(amax, a[-2])
else:
    max_idx = np.argmin([abs(a[idx]-cent), abs(a[idx-1]-cent)])
    if max_idx:
        print(amax, a[idx-1])
    else:
        print(amax, a[idx])

Submission status: Accepted

Solution code:
n=int(input())
lst=sorted(map(int,input().split()))
m=lst[-1]/2
anslst=[]
for i in range(n-1):
    anslst.append([abs(m-lst[i]),lst[i]])
anslst.sort()
print(int(m*2),anslst[0][1])

Submission status: Accepted

Solution code:
N=int(input())
L=list(map(int,input().split()))
L=sorted(list(set(L)))
M=L[-1]
K=M//2+M%2
S=[abs(i-K) for i in L]
print(M,L[S.index(min(S))])

Submission status: Accepted

Solution code:
from bisect import bisect
n=int(input())
lst=sorted(map(int,input().split()))
m=lst[-1]
index=bisect(lst,m/2)
if m!=lst[index]:
    q=lst[index]
    if 0<=index-1:
        p=lst[index-1]
        if abs(m/2-p)>=abs(m/2-q):
            print(m,q)
        else:
            print(m,p)
    else:
        print(m,q)
else:
    print(m,lst[index-1])

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
amax = max(A)
AA = sorted(A,key=lambda x: abs(amax/2-x))
if AA[0] == amax:
    print(amax,AA[1])
else:
    print(amax,AA[0])

Submission status: Accepted

Solution code:
def d_binomial_coefficients():
    N = int(input())
    A = sorted([int(i) for i in input().split()])  # ソートしておく

    n = A[-1]  # n を大きく、r を n/2 に近づけると comb(n, r) は大きい
    r = min(A[:-1], key=lambda x: abs(n / 2 - x))
    return f'{n} {r}'

print(d_binomial_coefficients())

Submission status: Accepted

Solution code:
import bisect

n = int(input())
A = sorted(list(map(int,input().split())))
ma = A[-1]
half = ma / 2
index = bisect.bisect_left(A,half)

if index != 0:
    ans = A[index-1] if half - A[index-1] <= A[index] - half else A[index]
else:
    ans = A[0]

print(ma,ans)

Submission status: Accepted

Solution code:
import numpy as np
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

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

n = A.pop()
m = getNearestValue(A, n/2)
print(n, m)

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())
a.sort(reverse=True)
max_a = a[0]
min_diff = float('inf')
for v in a[1:]:
    if abs(max_a/2 - v) <= min_diff:
        ans = v
        min_diff = abs(max_a/2 - v)
print(max_a, ans)

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
ai=a[-1]
aa=ai/2
ans=float("inf")
for i in range(n-1):
    tmp=abs(a[i]-aa)
    if tmp<ans:
        ans=tmp
        aj=a[i]
print(ai,aj)

Submission status: Accepted

Solution code:
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = sorted(LIST())
i = bisect_left(a[:-1], a[-1]/2)
if abs( a[-1]/2 - a[max(0,i-1)] ) <= abs( a[i] - a[-1]/2 ):
    print(a[-1], a[max(0,i-1)])
else:
    print(a[-1], a[i])

Submission status: Accepted

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

tmp = a[0]//2
s = 10**18
num = 0
for i in range(1, n):
    if(abs(tmp-a[i]) < s):
        s = abs(tmp-a[i])
        num = a[i]

print(a[0], num)

Submission status: Accepted

Solution code:
from bisect import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()
ai = a[-1]
mid = ai / 2
i = bisect(a, mid) - 1
j = i + 1
if j == n - 1:
    j = i
if abs(a[i] - mid) < abs(a[j] - mid):
    aj = a[i]
else:
    aj = a[j]
print(ai, aj)

Submission status: Accepted

Solution code:
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
mx = A[0]; A = A[1:]
mn = A[0]
for a in A[1:]:
    if abs(mn-mx/2) > abs(a-mx/2):
        mn = a
    else:
        break
print(mx, mn)

Submission status: Accepted

Solution code:
from bisect import bisect_left

n = int(input())
A = list(int(x) for x in input().split())
m = max(A)
A.remove(m)
A.sort()
index = bisect_left(A, m//2)
tmp = 10**18
ans = -1
for a in A[index-1:index+2]:
    if abs(a - m/2) < tmp:
        tmp = abs(a - m/2)
        ans = a
print(m, ans)

Submission status: Accepted

Solution code:
from bisect import bisect_right

n = int(input())
a = sorted(list(map(int, input().split())))

pos = bisect_right(a, a[-1]/2)
if pos == 0 or abs(a[-1]/2 - a[pos-1]) > abs(a[-1]/2 - a[pos]):
    print(a[-1], a[pos])
else:
    print(a[-1], a[pos-1])

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()


def main():
    """
    nをmax(A)にしていい理由が腑に落ちなかったので厳密証明。
    とはいえ証明は簡単で、M=max(A), m=(AのM以外の元), R=(M/2に一番近いAの元), r=(m/2に一番近いAの元)
    とすると
        comb(M, R) >= comb(M, r) >= comb(m, r)
    てだけでした。。。
    """
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    if N == 2:
        print(A[1], A[0])
        return
    idx = bisect_left(A, A[-1] // 2)
    a = A[idx]
    if idx > 0 and (A[idx] - A[-1] / 2) > (A[-1] // 2 - A[idx - 1]):
        a = A[idx - 1]
    print(A[-1], a)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    if N == 2:
        print(A[1], A[0])
        return
    idx = bisect_left(A, A[-1] // 2)
    a = A[idx]
    if idx > 0 and (A[idx] - A[-1] / 2) > (A[-1] // 2 - A[idx - 1]):
        a = A[idx - 1]
    print(A[-1], a)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
import sys
INFTY=sys.maxsize

def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a

def main(n,a):
    # order=[]
    # for i in range(n):
    #     order.append([a[i],i])
    s=sorted(a)
    ai=s[n-1]

    aj0=ai/2
    j=bisect_right(s, aj0)-1
    #print(s,aj0,j) 
    aj=s[j]
    if aj==aj0:
        return ai,aj

    if j+1<n:
        aj1=s[j]
        aj2=s[j+1]
        if aj0-aj1<=aj2-aj0:
            aj=aj1
        else:
            aj=aj2
    return ai,aj


if __name__=='__main__':
    n,a=readinput()
    i,j=main(n,a)
    print(i,j)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
st_n = a[0]
st_r = a[1]
m = st_r*(st_n-st_r)
for r in range(2,N):
    cn = a[r]*(st_n-a[r])
    if m < cn:
        st_r = a[r]
        m = cn
print(st_n,st_r)

Submission status: Accepted

Solution code:
import numpy as np


n = int(input())
A = np.array(sorted(map(int, input().split())))

a = A[-1]
A = A[:-1]
i = np.argsort(np.abs(A - a / 2))[0]
b = A[i]

print(a, b)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    n = in_n()
    a = sorted(in_nl())

    a_max = a[-1]
    diff = 10**9 + 7
    for i in range(n - 1):
        t = abs(a_max / 2 - a[i])
        if t < diff:
            a_mid = a[i]
            diff = t

    print(a_max, a_mid)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
n1=max(a)
n2=-n1
nc=n1/2
for m in a:
  if abs(m-nc)<abs(n2-nc) and m!=n1:
    n2=m
print (n1,n2)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
n1=max(a)
n2=-n1
nc=n1/2
a.pop(a.index(max(a)))
for m in a:
  if abs(m-nc)<abs(n2-nc):
    n2=m
print (n1,n2)

Submission status: Accepted

Solution code:
N=int(input())
l=list(map(int,input().split()))
A=max(l)
mid=(A//2)+1 if A%2!=0 else A//2
dis_min=float("Inf")
l.sort()
ans=1
for i in l:
   if dis_min>abs(i-mid):
      dis_min=abs(i-mid)
      ans=i
print(A,ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
N = a[-1]
ans = float('inf')
r = a[0]
for i in range(len(a)-1):
    if ans > abs(a[i]-N/2):
        ans = abs(a[i]-N/2)
        r = a[i]
print(str(N) +' '+ str(r))

Submission status: Accepted

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

sorted_a = sorted(a)
a_max = sorted_a[-1]

dif = []
for i,ai in enumerate(sorted_a[:n-1]):
    dif.append((i,abs(ai-(a_max/2))))

min_i = sorted(dif, key=lambda x:x[1])[0][0]
dif_min = sorted_a[min_i]

print(a_max, dif_min)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
amax = a[0]
na = a[1:]
d = {}
for el in na:
    d[el] = abs(el - amax//2)
ds = sorted(d.items(), key=lambda x:x[1])
print(amax, ds[0][0])

Submission status: Accepted

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

import bisect

mid = (a[-1]+1)//2
mid_idx = bisect.bisect_left(a, mid)

if abs(mid - a[mid_idx-1]) <= abs(a[mid_idx] - mid):
    print(a[-1], a[mid_idx-1])
else:
    print(a[-1], a[mid_idx])

Submission status: Accepted

Solution code:
import sys
import math
import numpy as np
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
INF = 10**9
mod = 10**9+7

def gnv(list, num):

    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

N = i()
a = l()
m = max(a)
if N == 2:
    print(m,min(a))
else:
    print(m,gnv(a,m/2))

Submission status: Accepted

Solution code:
import bisect
import sys

def main(args):
    
    n = int(input())
    A = list(map(int,input().split()))
    
    A.sort()
    
    ans = [max(A), 0]
    ind = bisect.bisect_left(A ,ans[0]//2)
    if A[ind] == ans[0]//2:
        ans[1] = ans[0]//2
    else:
        r1 = min(A[ind],ans[0]-A[ind])
        r2 = min(A[ind-1],ans[0]-A[ind-1])
        if r1 > r2:
            ans[1] = A[ind]
        else:
            ans[1] = A[ind-1]
    
    print(*ans)
    
if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
c=a[n-1]
if n==2:
  print(a[1],a[0])
  exit()
if c%2==0:
  p=c//2
  o=10**9
  for i in range(n):
    if abs(p-a[i])<=o:
      o=abs(p-a[i])
      ans=a[i]
else:
  p=c//2
  q=c//2+1
  o=10**9
  for i in range(n):
    if abs(p-a[i])<abs(q-a[i]):
      if abs(p-a[i])<o:
        o=abs(p-a[i])
        ans=a[i]
    else:
      if abs(q-a[i])<o:
        o=abs(q-a[i])
        ans=a[i]
print(c,ans)

Submission status: Accepted

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

import math

n = A.pop()
P_dif_A = sorted([(abs(a-n/2), a) for a in A])
r = P_dif_A[0][1]

print(n, r)

Submission status: Accepted

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

import math

n = A.pop()
P_dif_A = sorted([[abs(a-n/2), a] for a in A])
r = P_dif_A[0][1]

print(n, r)

Submission status: Accepted

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

a=sorted(a)


b=a.pop(-1)
mid=b/2
dist=10**9
for i in range(n-1):

    #できるだけ最大値から離れた値
    d=abs(mid-a[i])
    if d <dist:
        dist=d
        ans=a[i]

print(b,ans)

Submission status: Accepted

Solution code:
N = int(input())
*A, = map(int, input().split())
A.sort()
m = A[-1]
x = m / 2
ans = A[0]
for i in range(1, N-1):
    if abs(ans - x) > abs(A[i] - x):
        ans = A[i]
print(m, ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left

n = int(input())
A=  list(map(int,input().split()))
A.sort()
am = A[-1]
amin = 0
ans = 0
for a in A[:-1]:
  if min(a, am-a) > amin:
    amin = min(a,am-a)
    ans = a
    
print(am , ans)

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    a = sorted(map(int, input().split()))

    cost = float("INF")
    mn = 0
    mx = a[-1]
    for aa in a[:-1]:
        tmp = abs(mx - aa * 2)
        if tmp < cost:
            cost = tmp
            mn = aa
    print(mx, mn)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n=int(input())
L=list(map(int, input().split()))
a=max(L)
b=a
c=0
for i in range(n):
	if b>=abs(L[i]-a/2) and L[i]!=a:
		b=abs(L[i]-a/2)
		c=L[i]


print(a,c)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
min = a[-1]
j = 0
for i in range(n-1):
	if abs(a[i] - a[-1]//2) <= min:
		min = abs(a[i] - a[-1]//2)
		j = i
L = [a[-1],a[j]]
print(*L)

Submission status: Accepted

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

A.sort()

n = A[-1]
r1 = n / 2
temp = 10 ** 9
r = 0

for i, x in enumerate(A):
  if abs(r1 - x) <= temp and i != N-1:
    r = x
    temp = abs(r1 - x)

print(str(n)+" "+str(r))

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

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

# 最も大きい数と、その1/2との差が最も小さい数を選ぶ
A = sorted(A, reverse = True)
one = A[0]
diff = one
ans = -1
for i in range(1,len(A)):
  if abs(one / 2 - A[i]) < diff:
    diff = abs(one / 2 - A[i])
    ans = A[i]
    
print(one, ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)

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

if n==2:
    print(aa[0],aa[1])
    exit()

aa.sort()

nn=max(aa)

c=0
tmp=10**9

for a in aa:
    if abs(nn/2.0-a)<tmp:
        tmp=abs(nn/2.0-a)
        c=a

print(nn,c)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
amax = a[-1]
tmp1 = amax + 1
for i in a[:n-1]:
    tmp2 = i - amax/2
    if tmp2 > tmp1:
        break
    else:
        r = i
        tmp1 = abs(tmp2)
print(amax, r)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans1=max(a)
m=10**9+1
temp=ans1/2
i=0
for index,val in enumerate(a):
    if val==ans1: continue
    if abs(val-temp)<m:
        m=abs(val-temp)
        i=index
ans2=a[i]
print(ans1,ans2)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
m = max(A)
nya = m
mid = m/2
for i in range(n):
    if abs(A[i] - mid) <= nya:
        nya = abs(A[i]-mid)
        k = A[i]
print(m,k)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
M = a[-1]
m = a[0]
C = -1
for i in range(n):
  c = a[i]*(M-a[i])
  if C < c:
    C = c
    m = a[i]
  else:
    break
print(M, m, sep=' ')

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al = lin()
	
	ai = max(al)
	c = al.index(ai)
	pa(c)
	al.pop(c)
	pa(al)
	aj = min(al, key = lambda v : abs((ai/2)-v))
	
	print(ai, aj)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
def check(n, m):
    l = n // 2
    r = l + (n % 2 == 1)

    return min(abs(l - m), abs(r - m))


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

A.sort()
n = A[-1]
pd = float('inf')
for i in range(N - 1):
    a = A[i]
    d = check(n, a)
    if d < pd:
        b = a
        pd = d
print(n, b)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
x=a[n-1]/2
ans=a[0]
for i in range(1,n-1):
    if abs(ans-x)>abs(a[i]-x):
        ans=a[i]
print("{} {}".format(a[n-1],ans))

Submission status: Accepted

Solution code:
import bisect

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

if amax//2 in set(a):
  print(amax,amax//2)
else:
  ind = bisect.bisect_left(a,amax//2)
  MIN = min(abs(a[ind]-(amax//2)),abs(a[ind-1]-(amax//2)))
  if amax == 100 and a[ind] == 100:
    print(100,0)
    exit()
  
  if MIN == abs(a[ind]-(amax//2)):
    print(amax,a[ind])
  else:
    print(amax,a[ind-1])

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
A.sort()
first = A[-1]
second = max((min(x, first-x), x) for x in A[:-1])
print(first, second[1])

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
N = int(input())
A = sorted(list(map(int, input().split())))
tmp = A[-1]
ans = 0
for i in A[:-1]:
    if abs(A[-1] // 2 - i) < tmp:
        tmp = abs(A[-1] // 2 - i)
        ans = i
    elif A[-1] % 2 != 0 and abs(A[-1] // 2 - i + 1) < tmp:
        tmp = abs(A[-1] // 2 - i + 1)
        ans = i
print(A[-1], ans)

Submission status: Accepted

Solution code:
n = int(input())
arr = [int(a) for a in input().split()]

i = max(arr)
arr.remove(i)
j = min(arr, key=lambda a: abs(i/2-a))

print(i, j)