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:
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(n: int, a: "List[int]"):
    a.sort(reverse=True)
    r0 = a[0]
    r1 = a[1]
    h = r0 // 2
    for v in a[1:]:
        if abs(v - h) < abs(r1 - h):
            r1 = v
    print(r0, r1)
    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()))

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

max_a = max(a)
M = max_a // 2
min_diff = float('inf')
r = 0
for i in range(n):
    if abs(a[i] - M) < min_diff:
        min_diff = abs(a[i] - M)
        r = a[i]

print(max_a, r)

Submission status: Accepted

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

n = A[0]
m = n/2
c = 1e100
for a in A[1:]:
    if abs(m-a) < abs(m-c):
        c = a

print(n, c)

Submission status: Accepted

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

A.sort()

m = A[-1] / 2
diff = abs(A[0] - m)
r = A[0]
for a in A:
    tmp = abs(a - m)
    if tmp < diff:
        diff = tmp
        r = a

print(int(2 * m), r)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
max_a = max(a)
del a[-1]
target = int(1e9+1)
for aa in a:
    if abs(max_a - target*2) >= abs(max_a - aa*2):
        target = aa
print(max_a, target)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
n = max(A)
tmp = 0
ans = -1
for i in range(N):
	if min(A[i], n-A[i]) >= tmp:
		tmp = min(A[i], n-A[i])
		ans = A[i]

print(n, ans)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
l.sort()
dis = l[-1]
if l[-1]% 2 == 0:
    right = l[-1]//2
else:
    right = l[-1]//2+1
for i in range(n-1):
    if abs(l[i]-right) <= dis:
        dis = abs(l[i]-right)
        check = i
print("{} {}".format(l[-1],l[check]))

Submission status: Accepted

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

A.sort()
i = A[-1]
middle = i/2
j_right = bisect.bisect_right(A, middle)
left = A[j_right - 1]
right = A[j_right]
if abs(middle - left) <= abs(middle - right):
    j = left
else:
    j = right
print(i, j)

Submission status: Accepted

Solution code:
def solve(n, A):
    m = max(A)
    r = 0
    for a in A:
        if abs(m / 2 - r) > abs(m / 2 - a):
            r = a
    return (m, r)

_n = int(input())
_A = list(map(int, input().split()))
print(*solve(_n, _A))

Submission status: Accepted

Solution code:
#import numpy as np
#import math
import sys

read = lambda: sys.stdin.readline().rstrip()

class Solution(object):
    def binomial_coefficients(self, n, A):

        n0 = max(A)

        mid, r, cur = n0 / 2, -1, float("inf")
        for i in A:
            if i != n0:
                x = abs(mid - i)
                if x < cur:
                    r, cur = i, x
        return n0, r

def main():
    n0 = int(read())
    A0 = tuple(map(int, read().split()))

    res0, res1 = Solution().binomial_coefficients(n0, A0)

    print(res0, res1)
 
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
max_val = max(A)
half = max_val // 2
r = None
diff = float('inf')
for a in A:
    d = abs(half - a)
    if d < diff and a != max_val:
        diff = d
        r = a
print(max_val, r)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted([int(i) for i in input().split()])
a_i = (a[-1]+1)//2
ans = 0
for i in range(n):
    while abs(a_i - a[i]) < abs(a_i - ans):
        ans = a[i]
print(a[-1]," ",ans)

Submission status: Accepted

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

a.sort()
now = 1e18
ans = 0
for r in a:
    d = abs(r - a[n - 1] / 2)
    if d < now:
        ans = r
        now = d
print(a[n-1], ans)

Submission status: Accepted

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

max_a = max(a_list)
half_max = max_a / 2

near = max_a
near_ori = max_a
for a in a_list:
    if a == max_a:
        continue
    tmp = abs(a - half_max)
    if tmp < near:
        near = tmp
        near_ori = a
        
print(max_a, near_ori)

Submission status: Accepted

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

n = A[-1]
r_val = -float('inf')
r_row = None
for idx in range(N - 1):
    if r_val < min(n - A[idx], A[idx]):
        r_val = min(n - A[idx], A[idx])
        r_row = A[idx]
print(n, r_row)

Submission status: Accepted

Solution code:

n = int(input())
lst = list(map(int,input().split()))
lst.sort()

m = lst[-1]
line = m / 2
r = 10**10
for i in range(n):
    if abs(r-line) > abs(lst[i]-line):
        r = lst[i]
print(m,r)

Submission status: Accepted

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

ma = a[-1]

*b, = sorted((min(x, ma - x), x) for x in a[:-1])
_, r = b[-1]

print(ma, r)

"""
cmb(12,6) > cmb(12,5) > cmb(11,5)

cmb(n,r) = cmb(n-1,r) + cmb(n-1,r) > cmb(n-1,r)
rを決めたとき、nはできるだけ大きい方がよい=ma

cmb(ma,r)で最大となるもの
r=ma//2
"""

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(map(int, input().split()))
ai = A[-1]
aj = min(A, key=lambda a: max(a,ai-a))
print(ai, aj)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
n = A[0]
r = A[1]
for a in A[1:]:
    if abs((n/2)-r) > abs((n/2)-a):
        r = a
print(n,r)

Submission status: Accepted

Solution code:
n = int(input())
a = set(map(int, input().split()))
x = max(a)
z = 10 ** 9
for i in a:
    if abs(i - x / 2) < z:
        y = i
        z = abs(i - x / 2)
print(x, y)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
N = int(input())
a = sorted(list(map(int,input().split())))
ans = []
for i in range(1,N):
    candind = bisect.bisect_left(a,a[i]/2)
    if candind == i:
        candind -= 1
        cand = a[candind]
    elif candind == 0:
        cand = a[candind]
    else:
        if a[candind]-a[i]/2 <= a[i]/2-a[candind-1]:
            cand = a[candind]
        else:
            cand = a[candind-1]
    ans.append([a[i],cand])
ans.sort()
print(*ans[-1])

Submission status: Accepted

Solution code:
import bisect
N = int(input())
a = sorted(list(map(int,input().split())))
ans = []
for i in range(1,N):
    candind = bisect.bisect_left(a,a[i]/2)
    if candind == i:
        candind -= 1
        cand = a[candind]
    elif candind == 0:
        cand = a[candind]
    else:
        if a[candind]-a[i]/2 <= a[i]/2-a[candind-1]:
            cand = a[candind]
        else:
            cand = a[candind-1]
    ans.append([a[i],cand])
ans.sort(reverse=True)
x1 = ans[0][1]
ans2 = [ans[0]]
for i in range(1,len(ans)):
    if x1 >= ans[i][1]:
        break
    ans2.append(ans[i])
    x1 = ans[i][1]
print(*ans2[-1])

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort()
n = a[-1]
diff = 10**18
r = -1

for ai in a:
    if abs(n-2*ai)<diff:
        diff = abs(n-2*ai)
        r = ai

print(n, r)

Submission status: Accepted

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

x = max(A)

d = 10**18
for a in A:
    if a == x:
        continue
    tmp = abs(x/2-a)
    if tmp < d:
        d = tmp
        y = a

print(x, y)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
def getNearestValue(list, num):
	idx = np.abs(np.asarray(list) - num).argmin()
	return list[idx]

N=int(input())
A=list(map(int,input().split()))
A.sort()
n=A.pop()
r=getNearestValue(A,n/2)



print(n,r)

Submission status: Accepted

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

a.sort()
m = a[-1] // 2 + a[-1] % 2

i = bisect_left(a, m)

if i == 0:
    ans = str(a[-1]) + " " + str(a[0])
elif i == len(a)-1:
    ans = str(a[-1]) + " " + str(a[-2])
else:
    k = [a[i] - m, m - a[-1] % 2 - a[i-1]]
    s = min(k)
    s = k.index(s)
    ans = str(a[-1]) + " " + str(a[i-s])     

print(ans)

Submission status: Accepted

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

A.sort(reverse=True)
n = A[0]
ds = [(abs(n/2-A[i]),i) for i in range(1,N)]
ds.sort()
print(n,A[ds[0][1]])

Submission status: Accepted

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

As.sort()
from bisect import bisect_right
n = As[-1]
Xs = As[:-1]
s = [(abs(n/2-x),i) for i, x in enumerate(Xs)]
s.sort()
print(n, Xs[s[0][1]])

Submission status: Accepted

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

print(*ans)

Submission status: Accepted

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
A=many_int()

maxs=max(A)
A.remove(maxs)

mean = maxs//2
temp=0
temp_mean=10**10
for a in A:
    if abs(a-mean) < temp_mean:
        temp_mean = abs(a-mean)
        temp=a

print(str(maxs)+" "+str(temp))

Submission status: Accepted

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

a.sort()
ans1 = a[n-1]
ans2 = 0
minabs = 10**9+1
x = a[n-1]//2

for i in range(n-1):
    y = abs(a[i]-x)
    if a[n-1]%2 == 0:
        if minabs > y:
            ans2 = a[i]
            minabs = y
    else:
        if minabs > min(y,abs(a[i]-x-1)):
            ans2 = a[i]
            minabs = y
 
print(ans1,ans2)

Submission status: Accepted

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

a.sort()
ans1 = a[n-1]
minabs = 10**9+1
x = a[n-1]//2

for i in range(n-1):
    y = abs(a[i]-x)
    if a[n-1]%2 == 0:
        if minabs > y:
            ans2 = a[i]
            minabs = y
    else:
        if minabs > min(y,y-1):
            ans2 = a[i]
            minabs = y
  
print(ans1,ans2)

Submission status: Accepted

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

ans1 = max(A)
kouho = ans1 // 2
A.sort()
for i in range(N):
    if(A[i] >= kouho):
        kouho1 = A[i]
        kouho2 = A[i-1]
        break

if (ans1 == kouho1):
    ans2 = kouho2
elif (abs(ans1-2*kouho1) <= abs(ans1-2*kouho2)):
    ans2 = kouho1
else:
    ans2 = kouho2

print(ans1,ans2)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
M = max(A)
A.sort()
X = 0
for i in range(N-1):
  if abs(2*A[X]-M) > abs(2*A[i]-M):
    X = i
print(M, A[X])

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left as bi_l

n, *a = map(int, sys.stdin.read().split())

def main():
    a.sort()
    b = a[-1]
    c = (b + 1) // 2

    i = bi_l(a, c)
    if i == 0:
        return b, a[0]
    elif i == n - 1:
        return b, a[-2]
    else:
        res = a[i] if a[i] - c <= c - a[i-1] else a[i-1]
        return b, res

if __name__ == '__main__':
    ans = main()
    print(*ans, sep=' ')

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans1 = a[-1]
del a[-1]
long = ans1 

if ans1 % 2 == 0:
    x = ans1 // 2
    for i in a:
        y = abs(x - i) 
        if y < long:
            ans2 = i
            long = y
else:
    x = ans1 // 2
    z = ans1 // 2 + 1
    for i in a:
        y = min (abs(x - i),abs(z - i))
        if y < long:
            ans2 = i
            long = y
print(ans1,ans2)

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=sorted(LI())
    maxA = A[-1]
    ans = min(A[:-1],key = lambda x:abs((maxA/2 - x)))
    print(maxA,ans)
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]

target = a[0]/2

diff = 1000000000000

for i in a:
    if i == num:
        continue
    dif = abs(target-i)
    if dif < diff:
        diff = dif
        num_2 = i

print(num, num_2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = []
for i in range(n-1):
    b.append([abs(a[-1]/2 -a[i]),a[i]])
b.sort()
print(a[-1],b[0][1])

Submission status: Accepted

Solution code:

import sys
sys.setrecursionlimit(100000)
import numpy as np

directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])


def acinput():
    return list(map(int,input().split(" ")))


import numpy as np

directions = list(map(np.array, directions))


def serch(x, count):
    #print("top", x, count)
            

    for d in directions:
        nx = d+x
        #print(nx)
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1 
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)  
                continue
            if field[nx[0]][nx[1]] == "#":
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)    
                 
    return count

N=int(input())
s=acinput()
s=sorted(s)
#H, W = acinput()

#field = []

#for i in range(H):
#    field.append(list(input()))

res = s[-1]

v=10**9
res2=res
for ss in s:
    if abs(ss-res/2)<v:
        v = abs(ss-res/2)
        res2=ss

print(s[-1],res2)

Submission status: Accepted

Solution code:
n = int(input())
ls = list(map(int, input().split()))
# 二分探索で探す?
# あるkがあったとして,nCkが最大になるkはnが最大のときである.
# したがって,ソートした後にひとつずつ考えればよい.
ls = sorted(ls, key=lambda x: -x)

ans = [ls[0], ls[1]]
dif = ans[0] - ans[1] if ans[1] > ans[0] // 2 else ans[1]
for i in range(2, n):
    if ls[i] > ans[0] // 2:
        tmpdif = ans[0] - ls[i]
    else:
        tmpdif = ls[i]
    if tmpdif > dif:
        dif = tmpdif
        ans[1] = ls[i]
print(str(ans[0]) + " " + str(ans[1]))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=max(a)
a.remove(b)
l=[]
for i in range(n-1):
  l.append([abs(b/2-a[i]),a[i]])
l.sort()
print(b,l[0][1])

Submission status: Accepted

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

a.sort()

ai = a[-1]

ind = bisect.bisect_left(a,ai//2+1)

if a[ind-1] < ai-a[ind]:
    aj = a[ind]
else:
    aj = a[ind-1]

print(ai,aj)

Submission status: Accepted

Solution code:
import sys
import bisect

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()
A.sort()

amax = A.pop()
amid = bisect.bisect_left(A, amax/2)
if amid >= N-2:
	amid -= 1
# print(amax, A, amid)
a = A[amid]
b = A[amid-1]
if abs(amax/2 - A[amid]) < abs(amax/2 - A[amid-1]):
	print(amax, A[amid])
else:
	print(amax, A[amid-1])

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort()
n = a[-1]
flg = 0
ans = 0
for i in range(N):
  if flg < min(a[i],n-a[i]):
    flg = min(a[i],n-a[i])
    ans = a[i]
print(n,ans)

Submission status: Accepted

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

import sys
from bisect import bisect_left

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = [0] + LIST()

A.sort()

def check(x):
    idx = bisect_left(A, x)
    if abs(x - A[idx]) < abs(x - A[idx-1]):
        return A[idx], abs(x - A[idx])
    else:
        return A[idx-1], abs(x - A[idx-1])

# 真ん中を調べる
n = A[-1]
r1, dist1 = check(n // 2)
r2, dist2 = check(ceil(n, 2))
if dist1 < dist2:
    r = r1
else:
    r = r2
print(n, r)

Submission status: Accepted

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

import sys
from bisect import bisect_left

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = [0] + LIST()

A.sort()
x = A[-1] // 2
idx = bisect_left(A, x)
if abs(x - A[idx]) < abs(x - A[idx-1]):
    r1 = A[idx]
    dist1 = abs(x - A[idx])
else:
    r1 = A[idx-1]
    dist1 = abs(x - A[idx-1])
x = ceil(A[-1], 2)
idx = bisect_left(A, x)
if abs(x - A[idx]) < abs(x - A[idx-1]):
    r2 = A[idx]
    dist2 = abs(x - A[idx])
else:
    r2 = A[idx-1]
    dist2 = abs(x - A[idx-1])

if dist1 < dist2:
    r = r1
else:
    r = r2
print(A[-1], r)

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

b = bisect_left(A, A[-1]//2)
ans = 0
if b > 0:
  ans = b if min(A[b], A[-1]-A[b]) > min(A[b-1], A[-1]-A[b-1]) else b-1
print(A[-1], A[ans])

Submission status: Accepted

Solution code:
n=int(input())
A=sorted(list(map(float,input().split())))
a=A[-1]
b=a/2
c=a
for i in range(n):
  d=abs(A[i]-b)
  if d<c:
    c=d
    e=A[i]
print(int(a),end=" ")
print(int(e))

Submission status: Accepted

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

A.sort()
maxim = A.pop()

desire = maxim / 2
r = 0
for a in A:
    delta = abs(desire - a)
    if abs(desire - r) > delta:
        r = a

print(maxim, r)

Submission status: Accepted

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

maxNum = a[-1]
del a[-1]

median = maxNum / 2

# print(a)
# print('max:', maxNum)
# print('median:', median)

# Find the value closest to median
l = 0
r = n-2
# m = (l + r) // 2

while l <= r:
    m = (l + r) // 2
    # print(l, r, m)

    if a[m] == median:
        break
    if a[m] > median:
        r = m - 1
    else:
        l = m + 1

def fixBorder(median, idx):
    if idx < n-2 and abs(median - a[idx + 1]) < abs(median - a[idx]):
        return idx+1
    if idx > 0 and abs(median - a[idx - 1]) < abs(median - a[idx]):
        return idx-1
    else:
        return idx

# print('before:', m, a[m])
m = fixBorder(median, m)

# print('fixed:', m, a[m])
print(maxNum, a[m])

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

half = a_max/2
p = bisect_left(aa, half)
if abs(half - aa[p]) >= abs(half - aa[p-1]):
  print(a_max,aa[p-1])  
else:
  print(a_max,aa[p])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))
    v.sort()
    M = v[-1]
    d = INF
    ans = -1
    for c in v[:-1]:
        if abs(c - M//2) <= d:
            d = abs(c - M//2)
            ans = c
    print(M, ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
a=list(map(int, input().split()))
a.sort()
z=a[-1]/2
y=np.argmin([abs(a[i]-z) for i in range(n-1)])
print(a[-1], a[y])

Submission status: Accepted

Solution code:
import bisect

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

i=bisect.bisect_left(a,(a[n-1]+1)//2)
print(a[n-1], a[i-1] if ((a[n-1]+1)//2)*2<=a[i]+a[i-1] else a[i])

Submission status: Accepted

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

ans1=a[0]

b=ans1//2
ans2=0
for i in range(n):
    if abs(a[i]-b)<abs(ans2-b):
        ans2=a[i]

print(ans1,ans2)

Submission status: Accepted

Solution code:
import math

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

k=int(input())
a=sorted([int(i) for i in input().split()])
ma=a[-1]/2
#print(a)
eps=10**(-7)

m=a[-1]-ma
for i in range(k):
    m=min(abs(a[i]-ma),m)
print(a[-1],end=" ")
for i in range(k):
    if abs(abs(a[i]-ma)-m)<eps:
        print(a[i])
        break

Submission status: Accepted

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

m = max(a)
half = m / 2
sa = float("inf")
ans = 0
for i in a:
    if i != m:
        if abs(half - i) < sa:
            ans = i
            sa = abs(half - i)

print(m, ans)

Submission status: Accepted

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

a = sorted(a, reverse=True)
half = a[0] / 2
sa = float("inf")
ans = 0
for i in a[1:]:
    if abs(half - i) < sa:
        ans = i
        sa = abs(half - i)

print(a[0], ans)

Submission status: Accepted

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

desire = maxim//2
desire += maxim % 2
check = maxim
ans = 0
for a in A:
    delta = abs(desire-a)
    if delta < check:
        check = delta
        ans = a

print(maxim, ans)

Submission status: Accepted

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

    A = sorted(A)
    x = A[-1]
    del A[-1]
    b = x / 2

    m = 10**9
    y = A[0]
    for a in A:
        mm = abs(a - b)
        if mm < m:
            m = mm
            y = a

    print(x, y)


main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ;count = 0 ;pro = 1

n=int(input())
A=list(map(int,input().split()))
A.sort()
M=max(A)
m=0
# print(A)
for i in range(n-1):
    ai=A[i]
    # print(M,ai)
    if m<min(M-ai,ai):
        m=ai
        # print(m)
print(M,m)

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    a.sort()
    mr = 0
    for i in range(n):
        r = min(a[i], a[-1] - a[i])
        if r > mr:
            mr = a[i]
    print(a[-1], mr)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
import bisect
#from math import factorial
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
a_ls.sort()
max_a = max(a_ls)
a_ind = bisect.bisect_left(a_ls, max_a / 2)
print(max_a, a_ls[a_ind] if a_ls[a_ind] - max_a / 2 < max_a / 2 - a_ls[a_ind - 1] else a_ls[a_ind - 1])

Submission status: Accepted

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

N = A[-1]

R = A[0]
for i in A:
    if abs(N / 2 - R) > abs(N / 2 - i):
        R = i

print(N, R)

Submission status: Accepted

Solution code:
def N(a): #階乗 n!
    ans = 1
    for i in range(1,a+1):
        ans *= i
    return ans

def C(n,k): #組み合わせ nCk
    memo1 = N(n)
    memo2 = N(k)
    memo3 = N(n-k)
    return (memo1)//(memo2*memo3)


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

ans = 0
aim = a[n-1]//2

if a[n-1]%2!=0:
    aim2 = a[n-1]//2+1
else:
    aim2 = a[n-1]//2

memo = abs(a[0]-aim)
memo2 = 0
for i in range(n-1):
    if abs(memo) > abs(a[i]-aim):
        memo = abs(a[i]-aim)
        memo2 = a[i]

memo = abs(a[0]-aim2)
memo3 = 0
for i in range(n-1):
    if abs(memo) > abs(a[i]-aim2):
        memo = abs(a[i]-aim2)
        memo3 = a[i]

if abs(memo2-aim) > abs(memo3-aim2):
    ans = memo3
else:
    ans = memo2



print(a[n-1],ans)

Submission status: Accepted

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

biggest = max(a)

a.remove(biggest)
#print(a)
b = [abs(x-biggest/2) for x in a]

smol = min(b)
#print(b)
index = -1
for i in range(len(b)):
  if b[i] == smol:
    index = i
    break


r = a[index]

print(biggest, r)

Submission status: Accepted

Solution code:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    a.sort()
    mt = 0
    mn = 0
    for i in range(n):
        if mt < max(mt, min(a[i], a[-1] - a[i])):
            mt = max(mt, min(a[i], a[-1] - a[i]))
            mn = a[i]
    print(a[-1], mn)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
input()
a = [int(i) for i in input().split()]
if len(a) == 2:
    print(max(a), min(a))
    exit()
n = max(a)
r = a[0]
dif = abs(n // 2 - r)
for i in a:
    if abs(n // 2 - i) < dif:
        dif = abs(n // 2 - i)
        r = i
print(n, r)

Submission status: Accepted

Solution code:
n,*a = map(int,open(0).read().split())
a.sort(reverse=True)
ai = a[0]
aj = ai
for i in range(1,n):
    if abs(aj-ai/2)>=abs(a[i]-ai/2):
        aj = a[i]
print(ai,aj)

Submission status: Accepted

Solution code:
import bisect

def logcmb(a,b):
  if a<=b or a == 0 or b == 0:
    return 1
  return a*(a+1)//2 - (a-b)*(a-b+1)//2 - b*(b+1) // 2
n = int(input())
a = list(map(int,input().split()))
a.sort()
jdg = 0
for i in range(n):
  x = a[i]
  y = a[i]/2
  c = bisect.bisect_right(a,y)
  if c >= 1 and a[c]-y >= y-a[c-1]:
    r = a[c-1]
  elif c >= 1 and y-a[c-1] > a[c]-y:
    r = a[c]
  elif c == 0:
    r = a[0]
  if logcmb(x,r) >= jdg:
    jdg = logcmb(x,r)
    ans = x,r

print(*ans,sep=" ")

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())
a = sorted(a)
l = max(a)
b = a
b = sorted(b, key=lambda t: abs(t - l / 2))
r = b[0]
print(l, r)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[10**10]
a.sort(reverse=True)
c=a[0]
e=c//2
for i in range(1,n):
    b.append(abs(a[i]-e))
d=a[b.index(min(b))]
print(c,d)

Submission status: Accepted

Solution code:

N=int(input())
A=[int(x) for x in input().split()]
A=sorted(A,reverse = True)
b=float('inf')
for i in range(1,N):
  b=min(b,abs(A[0]/2-A[i]))
  if b ==abs(A[0]/2-A[i]):
    q=A[i]
  
print(A[0],q)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=max(a)
y=10**9
cnt=0
for i in range(n):
    if abs(a[i]-x/2)<y:
        y=abs(a[i]-x/2)
        z=a[i]
    if a[i]==x:
        cnt+=1
if z==x and cnt==1:
    print(x,0)
else:
    print(x,z)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
max_val = A[0]
min_val = float("inf")
for i in range(1,N):
    tmp_min = abs(max_val / 2 - A[i])
    if min_val > tmp_min:
        min_val = tmp_min
        ans_min = A[i]
print(max_val , ans_min)

Submission status: Accepted

Solution code:
n = int(input())
A = sorted([int(i) for i in input().split()], reverse=True)
a = A[0]/2
num = 100000000000
for i in range(1, n):
  if abs(a-A[i]) < num:
    ans = A[i]
    num = abs(a-A[i])
print(A[0], ans)

Submission status: Accepted

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

ai = a[-1]
j = bisect.bisect(a, ai/2)
if abs(ai/2 - a[j]) < abs(ai/2 - a[j-1]):
    aj = a[j]
else:
    aj = a[j-1]

print(ai, aj)

Submission status: Accepted

Solution code:
# D - Binomial Coefficients

import bisect

n = int(input())
a = sorted(list(map(int, input().split())))
    
idx = bisect.bisect_left(a, a[-1]//2)
tmp = float("inf")

try:
    if idx != n-1:
        tmp = abs(a[idx]-a[-1]/2)
        ans = [a[-1], a[idx]]
    if abs(a[idx-1] - a[-1]/2) < tmp:
        tmp = abs(a[idx-1] - a[-1]/2)
        ans = [a[-1], a[idx-1]]
    if abs(a[idx+1] - a[-1]/2) < tmp and idx+1 != n-1:
        ans = [a[-1], a[idx+1]]
except IndexError:
    pass

print(*ans)