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())
L = list(map(int,input().split()))
L .sort()

maxL = L[-1]
li = [abs(x-maxL/2) for x in L]

a = li.index(min(li))
print(maxL,L[a])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
r = a.pop(0)
s = r
temp = 0
for i in range(n-1):
    if abs(r - 2*a[i]) < s:
        s = abs(r - 2*a[i])
        temp = a[i]
print(r, temp)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
dif = 1000000000
best = a[0] // 2
ans = 0
for i in range(1, n):
    new_dif = abs(best - a[i])
    if dif <= new_dif:
        ans = a[i - 1]
        break
    dif = new_dif
else:
    print(a[0], a[1])
    exit()
print(a[0], ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
ma = a[-1]
mn = float("inf")
mni = -1
for i in range(n-1):
  if abs(2*a[i]-ma) < mn:
    mn = abs(2*a[i]-ma)
    mni = i
print(ma,a[mni])

Submission status: Accepted

Solution code:
import bisect

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

t, r = divmod(A[-1], 2)
idx = bisect.bisect_left(A, t)

if r == 1:
    if idx != 0:
        if abs(A[idx - 1] - t) < abs(A[idx] - t):
            idx = idx - 1
else:
    if idx != 0:
        if abs(A[idx - 1] - t) <= abs(A[idx] - t):
            idx = idx - 1

print(' '.join([str(A[-1]), str(A[idx])]))

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
an = a[-1]
a = a[:n - 1]
res = 10 ** 9
ans = 0
if an % 2 == 0:
    mid_l = an // 2
    mid_r = an // 2
else:
    mid_l = an // 2
    mid_r = (an + 1) // 2

for i in range(n - 1):
    if a[i] <= mid_l:
        if mid_l - a[i] < res:
            ans = a[i]
            res = mid_l - a[i]
    elif mid_r <= a[i]:
        if a[i] - mid_r < res:
            ans = a[i]
            res = mid_r - a[i]

print(an, ans)

Submission status: Accepted

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

nmax = max(a)
target = nmax/2

cur = a[0] if a[0] != nmax else a[1]
curdiff = abs(cur-target)

for i in range(n):
    if a[i] == nmax:
        continue

    diff = abs(a[i]-target)

    if diff < curdiff:
        curdiff = diff
        cur = a[i]

print(nmax, cur)

Submission status: Accepted

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

rc=float('inf')
rd=0
r=0
for i in a:
  if rc>abs(i-n/2):
    r=i
  rc=min(rc,abs(i-n/2))
  
print(n,r)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = sorted(list(map(int,input().split())))
    t = a[-1]
    s = t/2
    z = a[0]
    for i in range(1,n-1):
        if abs(a[i]-s)<abs(z-s):
            z = a[i]
    print(t,z)

if __name__ == "__main__":
    main()

Submission status: Accepted

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


def solve(n,a):
  a = list(sorted(a,reverse=True))
  first = a[0]
  b = a[1:]
  delta = [abs(x-first//2) for x in b]
  second = b[delta.index(min(delta))]
  return first,second

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

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
def main():
    _ = int(input())
    a = [int(an) for an in input().split()]
    a.sort()
    half_val = -(-a[-1] // 2)
    dist_list = [abs(half_val - an) for an in a[:-1]]
    min_index = dist_list.index(min(dist_list))
    print(f'{a[-1]} {a[min_index]}')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math 

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

m = max(a)
k = 0

for x in a:
    if abs((k * 2 - m)) > abs((x * 2 - m)):
        k = x

print(m, k)

Submission status: Accepted

Solution code:
from bisect import bisect_right
n=int(input())
a=sorted(list(map(int,input().split())))
x=a[-1]
c=bisect_right(a,x//2)
if x%2==0:
    if x//2 in a:
        print("{} {}".format(x,x//2))
    else:
        if a[c]-x//2>=x//2-a[c-1]:
            print("{} {}".format(x,a[c-1]))
        else:
            print("{} {}".format(x,a[c]))

        
else:
    if x//2 in a :
        print("{} {}".format(x,x//2))
    elif x//2+1 in a:
        print("{} {}".format(x,x//2+1))
    else:
        if a[c]-(x//2+1)>=x//2-a[c-1]:
            print("{} {}".format(x,a[c-1]))
        else:
            print("{} {}".format(x,a[c]))

Submission status: Accepted

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

Submission status: Accepted

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

m = max(lst)
r = m//2
k = float('inf')

for i in range(n):
  if lst[i] != m and abs(r-lst[i]) < abs(r-k):
    k = lst[i]
    
print(m, k)

Submission status: Accepted

Solution code:
# import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
enu = enumerate
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

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

fact = [1]
for i in range(1, N + 10):
    fact.append(fact[-1] * i % MOD)


def rev(x):
    return pow(x, MOD - 2, MOD)


def cmb(i, k):
    if i < k:
        return 0
    return fact[i] * rev(fact[k]) * rev(fact[i - k]) % MOD


A.sort()
if N == 2:
    print(A[1], A[0])
    exit()

mv = A[-1]
vm = mv // 2
bli = bisect_left(A, vm)
if bli == N - 1:
    print(mv, A[bli - 1])
elif bli == 0:
    print(mv, A[bli])
else:
    if vm - A[bli - 1] < A[bli] - vm:
        print(mv, A[bli - 1])
    else:
        print(mv, A[bli])

Submission status: Accepted

Solution code:

from bisect import bisect_left,bisect

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

a.sort()
ai=max(a)


#if ai%2==0:
#    ai2=ai//2+1
#else:
#    ai2=ai//2
ai2=ai/2

jj=bisect(a,ai2)

if jj+1<n:
    if abs(a[jj]-ai2)>abs(a[jj+1]-ai2):
        jj=jj+1
if jj-1>=0:
    if abs(a[jj]-ai2)>abs(a[jj-1]-ai2):
        jj=jj-1
    
if jj==n-1:
    jj=jj-1
    
aj=a[jj]

print(ai,aj)

Submission status: Accepted

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

import bisect

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

a.sort()

if n == 2:
    print(a[1], a[0])
    exit()
# value = comb(a[1], a[0], exact=True)
# ans = [a[1], a[0]]
# index = 0
# for i in range(2, n):
#     value_tmp = comb(a[i], a[index], exact=True)
#     x = a[i]
#     y = a[index]
#     diff = abs((x-2*y)//2)
#     while 1:
#         y_new = a[index+1]
#         diff_new = abs((x-2*y_new)//2)
#         if diff_new > diff:
#             break
#         else:
#             index += 1
#     if value_tmp > value:
#         ans = [a[i], a[index]]
#         # value = value_tmp
# print(*ans)

x = a[-1]
index = bisect.bisect_left(a[:n-1], x/2)

ans = []
ans.append([abs(x/2-a[index-1]), a[index-1]])
ans.append([abs(x/2-a[index]), a[index]])
# ans.append([abs(x/2-a[index+1]), a[index+1]])

ans.sort()

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

Submission status: Accepted

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

import bisect

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

a.sort()

if n == 2:
    print(a[1], a[0])
    exit()
# value = comb(a[1], a[0], exact=True)
# ans = [a[1], a[0]]
# index = 0
# for i in range(2, n):
#     value_tmp = comb(a[i], a[index], exact=True)
#     x = a[i]
#     y = a[index]
#     diff = abs((x-2*y)//2)
#     while 1:
#         y_new = a[index+1]
#         diff_new = abs((x-2*y_new)//2)
#         if diff_new > diff:
#             break
#         else:
#             index += 1
#     if value_tmp > value:
#         ans = [a[i], a[index]]
#         # value = value_tmp
# print(*ans)

x = a[-1]
index = bisect.bisect_left(a[:n-1], x/2)

ans = []
ans.append([abs(x/2-a[index-1]), a[index-1]])
ans.append([abs(x/2-a[index]), a[index]])
ans.append([abs(x/2-a[index+1]), a[index+1]])

ans.sort()

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

Submission status: Accepted

Solution code:
import itertools
n = int(input())
a = list(map(int, input().split()))
m = max(a)
t = (10**9)+1
for i in a:
    if abs(i-(m//2)) < t and i != m:
        t = abs(i-(m//2))
        s = i
print(m,s)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(map(int, input().split()))
p = a[-1]
c = 0
for i in range(n-1):
  if abs(a[i+1]-p/2) < abs(a[i]-p/2):
    c = a[i+1]
  else:
    break
print(p,c)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
maxa = max(a)
mini = [[] for _ in range(n)]
for i, v in enumerate(a):
    r = maxa - v
    mini[i] = [v, abs(v - r)]
mini.sort(key=lambda x: x[1])
if n == 2:
    print(maxa, min(a))
else:
    print(maxa, mini[0][0])

Submission status: Accepted

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

if n==2:
    print(max(l),min(l))
    exit()
maxi = max(l)
med = maxi//2
d = 10**9+1
ans = -1

for i in range(n):
    x = l[i]
    if l[i] > med:
        x = maxi-l[i]
    if med-x < d:
        d = med-x
        ans = l[i]

print(maxi,ans)

Submission status: Accepted

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

k = []
max_a = a[-1]
max_half = max_a / 2
for i in range(n):
    if a[i] >= max_half:
        if i == 0:
            k.append(a[i])
            break
        k.append(a[i])
        k.append(a[i-1])
        break
ans = 0
if len(k) == 1:
    ans = k[0]
else:
    if abs(max_half - k[0]) < abs(max_half - k[1]):
        ans = k[0]
    else:
        ans = k[1]

print(max_a, ans)

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N = int(input())
    As = [int(item) for item in input().split()]

    As.sort()
    max_num = max(As)

    res = 10**9 + 1
    if max_num % 2 == 0:
        if max_num //2 in As:
            res = max_num //2
        else:
            for item in As:
                if abs(max_num //2 - res) > abs(max_num //2 - item):
                    res = item
    else:
        if max_num //2 in As:
            res = max_num //2
        elif max_num // 2 + 1 in As:
            res = max_num //2 + 1 
        else:
            for item in As:
                if abs(max_num //2 - res) > abs(max_num //2 - item):
                    res = item
                if abs(max_num //2 + 1 - res) > abs(max_num //2 + 1 - item):
                    res = item


    print(max(As), res)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
cand=a[1]
for i in range(1,n-1):
  if abs(a[0]/2 - a[i]) > abs(a[0]/2 - a[i+1]):
    cand = a[i+1]
  else:
    break
print(a[0], cand)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    A.sort(reverse=True)
    n = max(A)
    med = n/2
    r = INF
    d = INF
    for a in A[1:]:
        if abs(a-med)<d:
            r = a
            d = abs(a-med)
    print(n,r)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
_ = int(input())
a = sorted(list(map(int, input().split())))
num0, num1, val = a[-1], 0, float('inf')

for i in a[:-1]:
    val0 = abs(i-num0/2)
    if val0 < val:
        num1 = i
        val = val0
print(num0, num1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, *a = map(int, open(0).read().split())
nn = max(a)
a.remove(nn)
nr = min(a, key=lambda x: abs(x - nn/2))
print(nn, nr)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ma = max(a)
a = a[:a.index(ma)] + a[a.index(ma)+1:]
l = []
for i in range(n-1):
    l.append([abs(ma-2*a[i]), "-" if ma-2*a[i] >= 0 else "+"])
l.sort()
print(ma,end=" ")
print((ma-l[0][0])//2) if l[0][1] == "-" else print((ma+l[0][0])//2)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

n = int(input())
al = list(map(int, input().split()))
al.sort()
ai = al[-1]
if ai%2 == 0:
    aj_best = ai//2
    ind = bisect_right(al, aj_best) - 1
    ind = ind if 0 <= ind < n else None
    val1 = al[ind] if ind is not None else 0

    ind = bisect_left(al, aj_best)
    ind = ind if 0 <= ind < n else None
    val2 = al[ind] if ind is not None else ai

    if abs(aj_best-val1) <= abs(aj_best-val2):
        aj = val1
    else:
        aj = val2


else:
    aj_best = ai//2
    ind = bisect_right(al, aj_best) - 1
    ind = ind if 0 <= ind < n else None
    val1 = al[ind] if ind is not None else 0

    ind = bisect_left(al, aj_best)
    ind = ind if 0 <= ind < n else None
    val2 = al[ind] if ind is not None else ai

    if abs(aj_best-val1) <= abs(aj_best+1-val2):
        aj = val1
    else:
        aj = val2

print(ai,aj)

Submission status: Accepted

Solution code:
n=int(input())

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

t.sort()

max_value = t[-1]

mid_value = 0

for a in t:
    if abs(max_value/2-a) < abs(max_value/2-mid_value):
        mid_value = a

print(max_value, mid_value)

Submission status: Accepted

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

P=max(A)
I=A.index(P)
del A[I]
Q=min(A,key=lambda x:abs(2*x-P))
print(P,Q)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
m = a[-1]
mid = m / 2

d = 10 ** 9
for ai in a[:-1]:
    x = abs(mid - ai)
    if x < d:
        ans = ai
        d = x

print(m, ans)

Submission status: Accepted

Solution code:
def resolve():
    import bisect
    N = int(input())
    A = sorted([int(i) for i in input().split()])
    if N == 2:
        print(max(A), min(A))
        return
    maxA = A[-1]
    half = maxA / 2
    i = bisect.bisect_left(A, half)
    if A[i] - half < half - A[i - 1]:
        print(maxA, A[i])
    else:
        print(maxA, A[i - 1])


resolve()

Submission status: Accepted

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

A_max = max(A)

A.remove(A_max)

X = [abs(a-(A_max//2)) for a in A]

X_min_id = X.index(min(X))

print(A_max,A[X_min_id])

Submission status: Accepted

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

A.sort()
x = A[-1]
A.pop()

z = x*10

for a in A:
    if abs(x-a*2) < abs(x-z*2):
        z = a

print(x, z)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    A.sort()
    n = max(A)

    i = 0
    while i < N - 2 and 2 * A[i] < n:
        i += 1

    if i in (0, N - 1):
        r = A[i]
    elif abs(2 * A[i] - n) < abs(2 * A[i - 1] - n):
        r = A[i]
    else:
        r = A[i - 1]

    print(n, r)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
l=sorted(map(int,input().split()))
m=l.pop()
t=h=m/2
r=0
for i in l:
  if (s:=abs(i-h))<t: t,r=s,i
print(m,r)

Submission status: Accepted

Solution code:
n=int(input())
l=sorted(map(int,input().split()))
m=l.pop()
h=m/2
t,r=h,0
for i in l:
  if (s:=abs(i-h))<t: t,r=s,i
print(m,r)

Submission status: Accepted

Solution code:
import sys

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

n = max(A)
mid = n / 2
r = float("inf")
for a in A:
    if a == n:
        continue
    if abs(mid - r) > abs(mid - a):
        r = a

print(n, r)

Submission status: Accepted

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

A.sort()
max_el = A[-1]
median = max_el//2
import bisect
median_ind = bisect.bisect_left(A,median)

if median_ind == 0:
    print(A[-1],A[0])
    exit()
if median_ind == N-1:
    print(A[-1],A[-2])
    exit()

abs_right = abs(A[median_ind]-median)
abs_left = abs(A[median_ind-1]-median)

if abs_right>abs_left:
    print(A[-1],A[median_ind-1])
    exit()

print(A[-1], A[median_ind])

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50

def run():
    n = int(sysread())
    A = list(map(int, sysread().split()))
    #print(A)
    A = sorted(A)
    #print(n, A)
    idx = bisect.bisect_left(A, A[-1] / 2)
    if idx == 0:
        print(f'{A[-1]} {A[0]}')
    elif idx == n-1:
        print(f'{A[-1]} {A[-2]}')
    else:
        val1 = A[idx]
        val2 = A[idx-1]
        if abs(val1 - A[-1] / 2) > abs(val2 - A[-1] / 2):
            print(f'{A[-1]} {val2}')
        else:
            print(f'{A[-1]} {val1}')


if __name__ == "__main__":
    run()

Submission status: Accepted

Solution code:
N=int(input())
*A,=map(int,input().split())
A.sort()
M=A[-1]
A=[-10**9]+A+[10**11]
from bisect import*
P=bisect_right(A,M/2)
if abs(A[P-1]-M/2)>abs(A[P]-M/2):
    m=A[P]
else:
    m=A[P-1]
print(M,m)

Submission status: Accepted

Solution code:
import bisect

n = int(input())
A = [int(_) for _ in input().split()]

A.sort()
x = A[-1]
y = bisect.bisect(A, x / 2)

if abs(A[y] - x / 2) < abs(A[y-1] - x / 2):
    print(x, A[y])
else:
    print(x, A[y-1])

Submission status: Accepted

Solution code:
import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
x = a[-1]
N = a[-1]//2

a = a[:-1]
y = bisect.bisect_left(a,N)
if len(a) <= y: ans = a[y-1]
else:
    ans = a[y]
    if 0 < y and abs(N-ans) > abs(N-a[y-1]): ans = a[y-1]
    if y < len(a)-1 and abs(N-ans) > abs(N-a[y+1]): ans = a[y+1]
print(x,ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.append(10**12)
MAX = A[N-1]
ans = N
for i in range(N):
    if abs(A[i] - MAX/2) < abs(A[ans] - MAX/2):
        ans = i
print(MAX,A[ans])

Submission status: Accepted

Solution code:
n = int(input())
A = sorted(list(map(int,input().split())))
for i in range(n):
    if A[i]*2>A[-1]:
        ind = i
        break
ind -= 1
a = A[ind]
b = A[-1]-A[ind+1]
if a>=b:
    print(A[-1],a)
else:
    print(A[-1],A[ind+1])

Submission status: Accepted

Solution code:
import bisect
n = int(input())
A = list(map(int,input().split()))
A.sort()
if n == 2:
  ans = [A[1],A[0]]
  print(*ans)
  exit()
MAX = A[-1]
target = MAX//2
ok = 0
ng = n
while abs(ok-ng)>1:
  mid = (ok+ng)//2
  if A[mid] <= target:
    ok = mid
  else:
    ng = mid
ans = [MAX,A[ok]]

nxt = ok+1
#print(A[nxt])
if nxt < n:
  dif0 = min(MAX-A[ok],A[ok])
  dif1 = min(MAX-A[nxt],A[nxt])
  if dif0 < dif1:
    ans[1] = A[nxt]
print(*ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b


# https://atcoder.jp/contests/abc094/tasks/arc095_b
n = a_int()
A = ints()
if len(A) == 2:
    A.sort()
    exit(*A[::-1])
ma = max(A)
ans = -1
d = 10**10
for a in A:
    if abs(a - ma / 2) < d:
        d = abs(a - ma / 2)
        ans = a


print(ma, ans)

Submission status: Accepted

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

d = n
r = -1
for a in A[:-1]:
    if n%2==0:
        t = abs(a - n//2)
        if t < d:
            d = t
            r = a
    else:
        t = min(abs(a - n//2), abs(a - (n//2+1)))
        if t < d:
            d = t
            r = a
print(n,r)

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()
M = As.pop()

diff = 10**18
for a in As:
    if abs(M/2-a)<diff:
        diff = abs(M/2-a)
        ans = a

print(M, ans)

Submission status: Accepted

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

n = int(input())
a = list(map(int, input().split()))
a.sort()
l = [ai for ai in a[:-1]]
l.sort(key=lambda x: abs(a[-1]/2-x))
print(a[-1], l[0])

Submission status: Accepted

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

i = A.pop()
j = None
best = float('inf')

for a in A:
    v = abs(a - i / 2)
    if v < best:
        best = v
        j = a

print(i, j)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[15]:


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


# In[18]:


a.sort()
ai = max(a)
diff = ai
old = diff
for x in a[:-1]:
    tmp = abs(x-ai/2)
    if tmp <= diff:
        aj = x
        diff = tmp
    if diff == old:
        break
    else:
        old = diff
print(ai,aj)


# In[ ]:

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
ma = max(a)
a.remove(ma)
num = 0
ind = 0
a.sort()
for i in range(N-1):
    if a[i] < ma//2:
        ind += 1

if ind == 0:
    print(ma,a[0])
    exit()
elif ind == N-1:
    print(ma,a[-1])
    exit()

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

Submission status: Accepted

Solution code:
import bisect

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

A.sort()

# 組み合わせの片方は最大値
n = A[-1]

# もう片方はnの半分に近い値
# 二分探索で最も近い値を見つける
mid = bisect.bisect(A, n/2)

# 一つ手前の値とどちらが近いかチェックして、近い方を出力する
if abs(n/2-A[mid-1]) > abs(n/2-A[mid]):
    print(n, A[mid])
else:
    print(n, A[mid-1])

Submission status: Accepted

Solution code:
import bisect

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

A.sort()
n = A[-1]
mid = bisect.bisect(A, n/2)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ai, aj = a[-1], a[-2]
for i in a[:-1]:
    if abs(ai - 2 * aj) > abs(ai - 2 * i):
        aj = i
print(ai, aj)

Submission status: Accepted

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

ai, aj = a[-1], a[-2]
for i in a[:-1]:
    aj = (i if abs(ai - 2 * aj) > abs(ai - 2 * i) else aj)
print(ai, aj)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
n = a[-1]
mid = a[-1] // 2
i = bisect_left(a[:-1], mid)

if i >= len(a) - 1:
    r = a[i - 1]
elif i == 0 or a[i] == mid:
    r = a[i]
elif a[i] - mid <= mid - a[i - 1]:
    r = a[i]
else:
    r = a[i - 1]

print(n, r)

Submission status: Accepted

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

ai = a[-1]
half_ai = ai // 2

i_left = bisect.bisect_left(a, half_ai)
i_right = bisect.bisect_right(a, half_ai)
if (a[i_left] == half_ai):
    print(ai, half_ai)
    exit()

if (i_left == i_right and i_left == 0):
    print(ai, a[0])
    exit()

if (abs(half_ai - a[i_left - 1]) >=
        abs(half_ai - a[i_right]) and i_right != len(a) - 1):
    print(ai, a[i_right])
else:
    print(ai, a[i_left - 1])

Submission status: Accepted

Solution code:
def solve():
  N = int(input())
  A = [-float('inf')]+list(map(int, input().split()))
  A.sort()
  ans = [A[-1]]
  n = A[-1]//2
  for i in range(1,N+1):
    if A[i]>n or i==N-1:
      if A[i]-n>n-A[i-1]:
        ans.append(A[i-1])
      else:
        ans.append(A[i])
      break
  return ans
print(*solve())

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
lst1 = list(map(int,readline().split()))

lst1.sort(reverse=True)

i = lst1[0]
lst1 = lst1[1:]

res = i/2
res2 = -1
minimum = 10**18
for j in lst1:
    if abs(j-res) < minimum:
        res2 = j
        minimum = abs(j-res)

print(i,res2)

Submission status: Accepted

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

if N == 2:
  print(*(max(A),min(A)))
  exit()
  
m = max(A)/2
nearest=-1
for i in range(N):
  if abs(A[i]-m)<abs(nearest-m):
    nearest = A[i]

print(*(max(A),nearest))

Submission status: Accepted

Solution code:
import math
import itertools

def swap(a,b):
    return max(a,b),min(a,b)

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

_ = input()
an = list(map(int,input().split()))
#an = [5,10,12]
an.sort()
target = an[-1]/2
res = min(enumerate(an), key=lambda x: abs(target - x[1]))
print(an[-1], res[1])

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
a = lr()
a.sort()
nn = a[-1]
ind = bisect.bisect_left(a,nn//2)
kouho1 = -inf
if ind > 0:
    kouho1 = a[ind-1]
kouho2 = a[ind]
if abs(nn/2 - kouho1) <= abs(nn/2 - kouho2):
    print(nn, kouho1)
else:
    print(nn, kouho2)

Submission status: Accepted

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

l.sort()
ans1 = l[-1]
ans2 = -1
diff = 1000000000
for i in range(n-1):
    if diff >= abs(l[i] - ans1//2):
        ans2 = l[i]
        diff = abs(l[i] - ans1//2)
print(ans1, ans2)

Submission status: Accepted

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

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

if n == 2:
    am = a[-1]
    amm = a[0]
else:
    am = max(a)
    ind = bisect.bisect_left(a,am//2)
    am1 = a[ind]
    am2 = a[ind-1]

    am1abs = abs(am/2-am1)
    am2abs = abs(am/2-am2)

    if am1abs <= am2abs:
        amm = am1
    else:
        amm = am2
    
print(am,amm)