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:
n=int(input())
a=[int(i) for i in input().split()]
MAX=a.index(max(a))
half=-1
for i in range(n):
    if abs(a[MAX]//2-a[half])>abs(a[MAX]//2-a[i]) and MAX!=i:
        half=i
print("{} {}".format(a[MAX],a[half]))

Submission status: Accepted

Solution code:
import bisect

N = int(input())
INF = 10**10
nums = list(map(int, input().split()))
nums.sort()
n_max = nums[-1]
n_half = n_max//2
nums = [-INF] + nums + [INF]
pos = bisect.bisect_left(nums, n_half)
if abs(n_half-abs(n_max-nums[pos])) >= abs(n_half-abs(n_max-nums[pos-1])):
  print(n_max, nums[pos-1])
else:
  print(n_max, nums[pos])

Submission status: Accepted

Solution code:
import bisect
from bisect import bisect_left, bisect_right

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

ma = max(a)
a.sort()

i = bisect_left(a, ma / 2)

if abs(ma / 2 - a[i]) < abs(ma / 2 - a[i-1]):
    print(ma, a[i])
else:
    print(ma, a[i-1])

Submission status: Accepted

Solution code:
# ABC094D - Binomial Coefficients (ARC095D)
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, dif = n / 2, -1, float("inf")
    for i in A:
        if i != n:
            x = abs(mid - i)
            if x < dif:
                r, dif = i, x
    print(n, r)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC094D - Binomial Coefficients (ARC095D)
from bisect import bisect_left as bs


def main():
    # pascal's triangle := mid area (nCn/2) is the biggest -> bisect
    N = int(input())
    A = sorted(map(int, input().split()))
    if N == 2:
        print(A[1], A[0])
        return
    n, idx = A[-1], bs(A[:-1], A[-1] // 2)
    cand = [(abs(A[i] - n / 2), A[i]) for i in (idx - 1, idx, idx + 1)]
    r = min(cand)[1]
    print(n, r)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC094D - Binomial Coefficients (ARC095D)
from bisect import bisect_left as bs


def main():
    N = int(input())
    A = sorted(map(int, input().split()))
    if N == 2:
        print(A[1], A[0])
        return
    n, idx = A[-1], bs(A[:-1], A[-1] // 2)
    r = min(
        (abs(A[idx - 1] - n / 2), A[idx - 1]),
        (abs(A[idx] - n / 2), A[idx]),
        (abs(A[idx + 1] - n / 2), A[idx + 1]),
    )
    print(n, r[1])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC094D - Binomial Coefficients (ARC095D)
def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    n = max(A)
    r = A[0] if A[0] != n else A[1]
    cur = r * (n - r)
    for i in A:
        if i != n:
            x = i * (n - i)
            if x > cur:
                r, cur = i, x
    print(n, r)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 0
d_min = a[-1]
for i in range(n-1):
  d = abs(a[-1]/2 - a[i])
  if d < d_min:
    d_min = d
    ans = a[i]
    
print('{} {}'.format(a[-1], ans))

Submission status: Accepted

Solution code:
n,a=open(0);*a,=map(int,a.split());m=max(a);print(m,min((abs(m/2-i),i)for i in a)[1])

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(map(int,input().split()))
ans=a[-1]
m=float('inf')
k=0
for i in range(n):
    if abs(ans/2-a[i])<m:
        m=abs(ans/2-a[i])
        k=i
print(ans,a[k])

Submission status: Accepted

Solution code:
"""
comb(n,r)
a1, a2, ..., an から2つの数をcomb(ai,aj)が最大になるように選ぶ


2 4 6 9 11
"""

n = int(input())
As  = list(map(int, input().split()))
A_sort = sorted(As)
A_max = max(As)

ans = 100000000000
for a in A_sort[:-1]:
    d1 = abs(A_max / 2 - ans)
    d2 = abs(A_max / 2 - a)
    if d1 >= d2:
        ans = a
print(A_max,ans)

Submission status: Accepted

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

l = max(a)
a.remove(l)

minimum = 10 ** 10
p = (l+1) / 2

for v in a:
    if abs(v - p) <= abs(minimum - p):
        minimum = v

print(l,minimum)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    N = II()
    a_li = LI()

    a_li.sort()

    n = a_li[-1]
    
    dif = INF
    prev_dif = dif
    for a in a_li[:-1]:
        dif = min(abs(n/2 - a), dif)
        if dif != prev_dif:
            r = a
            prev_dif = dif

    print(n, r)


main()

Submission status: Accepted

Solution code:

import bisect
import collections
import itertools

def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint2d(rows): return [getints() for _ in range(rows)]
def getgrid(rows): return [input() for _ in range(rows)]
def array1d(n, value): return [value for _ in range(n)]
def array2d(n, m, value): return [array1d(m, value) for _ in range(n)]

n = getint()
values = list(sorted(getints()))

mx = max(values)
idx1 = bisect.bisect_left(values, mx // 2)
idx2 = idx1 - 1 if idx1 > 0 else idx1

if abs(mx - values[idx1] * 2) < abs(mx - values[idx2] * 2):
    idx = idx1
else:
    idx = idx2

print(mx, values[idx])

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

a = A[-1]
b = float(a) / 2
i = bisect_left(A, b)
if a % 2 == 0 and A[i] == a // 2:
    print(a, a // 2)
else:
    if b - A[i-1] <= A[i] - b:
        print(a, A[i-1])
    else:
        print(a ,A[i])

Submission status: Accepted

Solution code:
n=int(input())
box=sorted(list(map(int,input().split())))
if len(box)==2:print(max(box),min(box));exit()
max_box=max(box)
target=max_box//2
if max_box%2==0:
    if target not in box:
        box.append(target)
        box=sorted(box)
        add=box.index(target)
        if abs(target-box[add-1])>abs(target-box[add+1]):
            print(max_box,box[add+1])
        else:
            print(max_box,box[add-1])
    else:print(max_box,target)
else:
    if (target+1 not in box) and (target not in box):
        box.append(target)
        box=sorted(box)
        add=box.index(target)
        if abs(target-box[add-1])>abs(target+1-box[add+1]):
            print(max_box,box[add+1])
        else:print(max_box,box[add-1])
    else:
        if target in box:print(max_box,target)
        else:print(max_box,target+1)

Submission status: Accepted

Solution code:
from bisect import bisect_left
from bisect import bisect_right

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

ai = a[-1]
a.pop(-1)
aj = 0
middle = ai//2 if ai % 2 == 0 else ai//2+1
if len(a) == 1:
    aj = a[0]
elif a[bisect_left(a, middle)] == middle:
    aj = middle
elif abs(a[bisect_left(a, middle)]-middle) < abs(a[bisect_right(a, middle)-1]-middle):
    aj = a[bisect_left(a, middle)]
else:
    aj = a[bisect_right(a, middle)-1]

print(ai,aj)

Submission status: Accepted

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

Submission status: Accepted

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

n = max(a)
a.remove(n)
d = list(map(lambda ai: abs(n / 2 - ai), a))
i = d.index(min(d))
r = a[i]

print(n, r)

Submission status: Accepted

Solution code:
n=int(input())
l=sorted(list(map(int,input().split())))
n1=l[-1]
n2=0
for i in l[:n]:
    tmp=min(i,n1-i)
    if tmp>n2:
        n2=i
print(n1,n2)

Submission status: Accepted

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

i = 0

for a in a_array:
    i = max(i, a)

j = 0


for a in a_array:
    if a == i:
        continue
    if abs(j - i/2) > abs(a - i/2):
        j = a

print(i, j)

Submission status: Accepted

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

def main():
    N = int(input())
    a = list(map(int, input().split()))

    ans1 = max(a)
    half = ans1 / 2
    min_ = abs(a[0] - half)
    ans2 = a[0]
    for i in range(1, N):
        if a[i] != ans1:
            tmp = abs(a[i] - half)
            if tmp <= min_:
                ans2 = a[i]
                min_ = tmp
    print(ans1, ans2)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import bisect

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

a.sort()
a_max = a.pop(-1)
a_half_1 = a[min(bisect.bisect_left(a, a_max // 2), len(a) - 1)]
a_half_2 = a[max(bisect.bisect_left(a, a_max // 2) - 1, 0)]
if abs(a_max / 2 - a_half_1) < abs(a_max / 2 - a_half_2):
    a_half = a_half_1
else:
    a_half = a_half_2

print(a_max, a_half)

Submission status: Accepted

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

Submission status: Accepted

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

N = max(a)
a.remove(N)
N2 = N/2

li = [abs(N2 - k) for k in a]
index = li.index(min(li))
m = a[index]

print("{0} {1}".format(N, m))

Submission status: Accepted

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

N = max(a)
a.remove(N)
N2 = N/2

li = [abs(N2 - k) for k in a]
index = li.index(min(li))

print("{0} {1}".format(N, a[index]))

Submission status: Accepted

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

a.sort()

N = a[-1]
a.pop()

li = [abs(N/2 - k) for k in a]
index = li.index(min(li))

print("{0} {1}".format(N, a[index]))

Submission status: Accepted

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

N = max(a)
a.remove(N)

li = [abs(N/2 - k) for k in a]
index = li.index(min(li))

print("{0} {1}".format(N, a[index]))

Submission status: Accepted

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

a1 = A[-1]
ref = a1/2
cmp = np.abs(ref - A[0])
a2 = A[0]
for a in A[1:-1]:
    if cmp > np.abs(ref - a):
        a2 = a
        cmp = np.abs(ref-a)
print(a1,a2)

Submission status: Accepted

Solution code:
N = int(input())
A_arr = [int(x) for x in input().split()]

A_arr.sort()
Ai = A_arr[-1]
Aj = sorted(A_arr[:-1], key=lambda x:abs(2*x-Ai))[0]

print(Ai, Aj)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
T = max(A)/2
M = max(A)
S = A[0]

for i in range(N-1):
  if M >= abs(A[i] - T):
    M = abs(A[i] - T)
    S = A[i]

print(str(A[N-1])+" "+str(S))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from bisect import bisect_left

n = int(input())
a = [int(s) for s in input().split()]
a.sort()
ai = a[-1]
j = bisect_left(a, ai // 2)
if j == 0:
    aj = a[j]
elif j == n-1:
    aj = a[j-1]
else:
    aj = a[j] if 2 * a[j] - ai <= ai - 2 * a[j-1] else a[j-1]
print(ai, aj)

Submission status: Accepted

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import perm
from scipy.misc import comb
# from scipy.special import perm
# from scipy.special import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

########
n = i_inpl()
a = l_inpl()
max_v = max(a)/2

an = INF
for ai in a:
    if abs(an-max_v) > abs(ai-max_v) and max(a) != ai:
        an = ai
print(max(a), an)

Submission status: Accepted

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

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7

n = int(input())
a = list(map(int,input().split()))
a.sort()
m = max(a)
l = 0
ans = a[0]
for i in a[:n-1]:
    if l < min(m-i,i):
        l = min(m-i,i)
        ans = i
print(m,ans)

Submission status: Accepted

Solution code:
i = int(input())
a = list(map(int, input().split()))
a.sort()
a = a[::-1]
# print(a)
n = a[0]
m = n // 2
diff = 100200300400500
ans = -1
for i in a[1:]:
    r1 = abs(m - i)
    r2 = abs(m - n + i)
    if min(r1, r2) < diff:
        diff = min(r1, r2)
        ans = i
print(n, ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left
from sys import stdin



def solve(a):
    a.sort()
    mid = a[n-1]/2
    ai = a[bisect_left(a, mid)-1]
    aj = a[bisect_left(a, mid)]
    am = ai if abs(mid-ai) <= abs(mid-aj) else aj

    print(a[n-1], am)


if __name__ == '__main__':
    n = int(input())
    a = list(map(int, stdin.readline().split()))
    solve(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce
import bisect

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


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

A.sort()
mx = A[N-1]
A.pop()
# print(A)
_r = bisect.bisect_right(A, mx/2)
_l = bisect.bisect_left(A, mx/2)
if N == 2:
    # A = A[::-1]
    A = [mx, A[0]]
    print(*A)
    exit()
# print(mx/2)
# print(_r, _l)
if _r > N-2:
    _r = N-2
if _l > N-2:
    _l = N-2

if abs(A[_l-1]-(mx/2)) > abs(A[_l]-(mx/2)):
    print(mx, A[_l])
else:
    print(mx, A[_l-1])

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
a = max(A)
import math
import bisect
mid = a / 2
left = bisect.bisect_left(A, mid)
min_diff = 1<<50
for diff in [-1, 0]:
    at = left + diff
    diff_abs = abs(A[at]-mid)
    if diff_abs < min_diff:
        min_diff = diff_abs
        b = A[at]

print("%d %d" % (a, b))

Submission status: Accepted

Solution code:
from bisect import bisect

n = int(input())
A = list(map(int, input().split()))
A.sort()
b = A.pop()
m = b / 2
i = bisect(A, m)
A.insert(i, m)

if i == 0:
    print(b, A[1])
elif i == len(A) - 1:
    print(b, A[-2])
elif A[i] - A[i - 1] < A[i + 1] - A[i]:
    print(b, A[i - 1])
else:
    print(b, A[i + 1])

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans1 = A[-1]
ans2 = -1
for i in range(0, N-1):
	if abs(A[i]-ans1/2) < abs(ans2-ans1/2):
		ans2 = A[i]
print(str(ans1) + ' ' + str(ans2))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = max(a)
ans = ' '.join((
    str(m),
    str(max(sorted(a), key=lambda x: min(x, m - x)))
))
print(ans)

Submission status: Accepted

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

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


i = bisect_left(a, a[-1]/2)
if i > 0:
    if abs(a[-1]/2 - a[i]) < abs(a[-1]/2 - a[i-1]):
        print(a[-1], a[i])
    else:
        print(a[-1], a[i-1])
else:
    print(a[-1], a[i])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
mx = max(a)
d = a[0]
t = mx/2
if n==2:
    print(max(a),min(a))
    exit()
for i in a:
    if abs(i-t)<abs(d-t):
        d = i
print(mx,d)

Submission status: Accepted

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

n = max(A)
ans = 0
for a in A:
    if abs(n/2 - a) < abs(n/2 - ans):
        ans = a
print(n, ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from bisect import bisect_left

n = input()
a = list(map(int, input().split()))
a.sort()
N = a[-1]
i = bisect_left(a, (N + 1) // 2)
K1 = a[i]
K2 = a[i - 1]
if K1 != N and N - K1 > K2:
    K = K1
else:
    K = K2
print(N, K)

Submission status: Accepted

Solution code:
n = int(input())
an = [int(i) for i in input().split()]
ans_a = max(an)
ans_b = 0
for i in an:
  if min(ans_a - ans_b,ans_b) < min(ans_a - i,i):
    ans_b = i
print(ans_a,ans_b)

Submission status: Accepted

Solution code:
n = int(input())
an = [int(i) for i in input().split()]
ans_a = max(an)
ans_b = 0
for i in an:
  if min(ans_a - ans_b,ans_b) < min(ans_a - i,i):
    ans_b = i
print(str(ans_a) + ' ' + str(ans_b))

Submission status: Accepted

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

ai = max(a)
a.remove(ai)
b = list(map(lambda x: abs(x - ai / 2), a))
aj = min(b)+(ai/2) if min(b)+(ai/2) in a else min(b)-(ai/2)
print(ai, abs(int(aj)))

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
M=max(X)
X.remove(M)
m=min([abs(2*x-M) for x in X])
if (M+m)//2 in X:
    m=(M+m)//2
else:
    m=(M-m)//2
print(M,m)

Submission status: Accepted

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

ans1 = max(A)
diff = 10 ** 9 
for i in range(N):
  if abs(A[i] - ans1 / 2) <= diff:
    ans2 = A[i]
    diff = abs(A[i] - ans1 / 2)
print(ans1, ans2)

Submission status: Accepted

Solution code:
import bisect

n = int(input())
num_list = sorted([ int(v) for v in input().split() ])

x = num_list[-1]
x_half = x / 2
y = bisect.bisect_left(num_list,x_half)
if y != 0:
    if y == n-1:
        y -= 1
    else:
        if abs(num_list[y] - x_half) >= abs(num_list[y-1] - x_half):
            y -= 1
print(x,num_list[y])

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
ans1=a[0]
num=99999999999999
for i in range(1,n):
    if ans1%2==0:
        u=abs(a[i]-ans1//2)
        if num>u:
            num=u
            ans2=a[i]
    else:
        u,v=abs(a[i]-ans1//2),abs(a[i]-(ans1//2+1))
        if num>min([u,v]):
            num=min([u,v])
            ans2=a[i]
print(ans1,ans2)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
mx = max(A)
A.remove(mx)
ans = 10**9
ans_dist = ans
med = mx // 2

for a in A:
    if ans_dist > abs(med - a):
        ans, ans_dist = a, abs(med - a)
print(mx, ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
mx = max(A)
ans = mx * 3
med = mx // 2
for a in A:
    if mx == a:
        continue
    if abs(med - ans) > abs(med - a):
        ans = a
print(mx, ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = max(A) * 3
mx = max(A)
med = mx // 2
for a in A:
    if mx == a:
        continue
    if abs(med - ans) > abs(med - a):
        ans = a
print(mx, ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=max(a)
c=b
d=0
for i in a:
  if c>=abs(b/2-i):c=abs(b/2-i);d=i
print(b,d)

Submission status: Accepted

Solution code:
def main():
	N = int(input())
	A = list(map(int, input().split()))
	A.sort()
	h = A[-1]//2
	c = A[0]
	for a in A:
		if a == A[-1]:
			continue
		if abs(h-a) <= abs(h-c):
			c = a
	print(" ".join([str(A[-1]), str(c)]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
x=a[-1]
ans=[x,0]
for i in a:
    if x>i and abs(x//2-i)<abs(x//2-ans[1]):
        ans[1]=i
    if x>i and x%2 and abs((x+1)//2-i)<abs((x+1)//2-ans[1]):
        ans[1]=i

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

Submission status: Accepted

Solution code:
import math
import sys


if __name__ == '__main__':
    n = int(input())
    a_list = list(map(int, input().split()))

    max_a = max(a_list)
    a_list.remove(max_a)

    min_diff = sys.maxsize
    answer1 = max_a
    answer2 = -1
    for i in range(n-1):
        diff = math.fabs(max_a/2 - a_list[i])
        if min_diff > diff:
            min_diff = diff
            answer2 = a_list[i]

    print(str(answer1) + " " + str(answer2))

Submission status: Accepted

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

if n-a[i]>min(a[i-1],n-a[i-1]):
    r = a[i]
else:
    r = a[i-1]
print('{} {}'.format(n,r))

Submission status: Accepted

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

a.sort()
upper=bisect.bisect_left(a,a[-1]/2)
lower=upper-1 if upper>0 else 0
b = a[lower] if abs(a[-1]/2-a[lower])<=abs(a[-1]/2-a[upper]) else a[upper]
print(a[-1],b)

Submission status: Accepted

Solution code:
n = int(input())
aa = sorted(list(map(int, input().split())))
nn = aa[-1]
aa = aa[0:-1]
ds = sorted([(abs(a - (nn / 2)), a) for a in aa])
r = ds[0][1]
print(nn, r)

Submission status: Accepted

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

comb1 = max(a)
comb2 = comb1//2
a.sort()
p = 0
keep = float("inf")
for i in range(n):
    if abs(a[i] - comb2) <= keep:
        p = a[i]
        keep = abs(a[i]-comb2)

if comb1 == p:
    print(comb1,0)
else:
    print(comb1,p)

Submission status: Accepted

Solution code:
n=int(input())
a_list=list(map(int,input().split()))
a_list.sort()
M=a_list[n-1]
m=a_list[0]
d=M/2-m
for i in a_list[:n-1]:
    if abs(M/2-i)<d:
        d=abs(M/2-i)
        m=i
print(M)
print(m)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
x=a[n-1]
a=a[0:n-1]
y=x
z=x
for j in range(n-1):
  if z>=abs(abs(x-a[j])-a[j]):
    y=a[j]
    z=abs(abs(x-a[j])-a[j])
print(x,y)

Submission status: Accepted

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

a = sorted(a)

import numpy as np
def getNearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]
  
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

tmp0 = a[n-1] / 2
tmp1 = getNearestValue(a[0:n-1], tmp0)
print(a[n-1], tmp1)

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    a = f()

    a = sorted(a)

    mx = a[-1]
    
    midiff = abs(mx/2 - a[0])
    minum = a[0]

    for i in a[:-1]:
        if abs(i - mx/2) < midiff:
            midiff = abs(mx/2 - i)
            minum = i
    
    print(mx, minum)

    

solve()

Submission status: Accepted

Solution code:

n = int(input())
As = list(map(int,input().split(" ")))

As.sort()
if As[-1] % 2 == 0:
    r = As[-1]//2
    l = As[-1] // 2
else:
    r = As[-1] // 2
    l = As[-1] -r

ans = 10e9
for a in As:
    if abs(a-r) < abs ( ans - r ):
        ans = a
    if abs(a-l) < abs ( ans - l ):
        ans = a

print(As[-1],ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
N = max(A)
l,r = 0,0
for i in A:
    if i > N/2:
        r = i
        break
    l = i
if N/2 - l > r - N/2:
    print(N,r)
else:
    print(N,l)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
n=max(a)
a.remove(n)
t=n
for i in a:
    if(t>abs(n/2-i)):
        t=abs(n/2-i)
        r=i
print(n,r)

Submission status: Accepted

Solution code:
"""
combination
右が固定 : 左は大きければ大きいほうが良い
左が固定 : 右は1/2に近ければ近いほうが良い
これを左から順に探していくので良い
"""

N = int(input())
As = list(map(int,input().split()))
As = sorted(As, reverse=True)
l = As[0]
r = As[1]

for a in As[2:]:
    if abs(l/2-a) < abs(l/2-r):
        r = a
print(l,r)

Submission status: Accepted

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

a.sort()

ai = a.pop(-1)

ai_half = ai / 2

dist = []
for i in range(n-1):
    dist.append(abs(a[i] - ai_half))

idx = min(range(n-1), key=dist.__getitem__)

aj = a[idx]

print(ai, aj)

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]
    r = n/2.0

    min_diff = float("inf")
    bi = 0
    for i in range(len(A)-1):
        if abs(A[i]-r) < min_diff:
            min_diff = abs(A[i]-r)
            bi = i

    print(n,A[bi])







# 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:
n=int(input())
x=[int(i) for i in input().split()]
t=sorted(x)
m=t.pop()
a=[(i,abs(m/2-i)) for i in t]
a=sorted(a,key=lambda x:x[1])
print(m,a[0][0])

Submission status: Accepted

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

ma = max(a)
s = [ abs(i*2-ma)  for i in a]
print(ma,a[s.index(min(s))])

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
a_i = max(A)
r = a_i / 2
a_j = 0
for a in A:
    if abs(a - r) < abs(a_j - r):
        a_j = a
print(a_i, a_j)

Submission status: Accepted

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


def solve(n: int, a: "List[int]"):
    mx = max(a)
    a.sort()
    l = -1
    r = n
    while r - l > 1:
        m = (r + l) // 2
        if a[m] > (mx + 1) // 2:
            r = m
        else:
            l = m
    target = (mx + 1) // 2
    if r == n - 1 or abs(target - a[l]) < abs(target - a[r]):
        print(mx, a[l])
    else:
        print(mx, a[r])
    return


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:
n = int(input())
A = list(map(int, input().split()))

A.sort()

def comb(x, y):
    p = 1
    d = 1
    for i in range(y):
        p *= x - i
        d *= y -i
    return p // d

diff = -1
ans = [A[n-1], -1]
for a in A[:n-1]:
    new_diff = min(a, A[n-1]-a)
    if diff < new_diff:
        diff = new_diff
        ans[1] = a
print(*ans)

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr,reverse=True)
amax=arr[0]
rbest=amax//2
arr=arr[1:]
r=0
diff=10**18
for i in range(n-1):
  tmp=abs(rbest-arr[i])
  if tmp<diff:
    diff=tmp
    r=arr[i]
print(amax,r)