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())
ax, *A = sorted(map(int, input().split()), reverse=True)
median = ax/2
mid = A[0]
for a in A[1:]:
    if abs(median-mid) > abs(median-a):
        mid = a

print(ax, mid)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#094_D
n = int(input())
a = sorted(list(map(int, input().split())))
m = a[-1]
mid = m / 2
l = 10 ** 10
for i in range(n-1):
    if abs(a[i] - mid) < abs(l - mid):
        l = a[i]
print(m, l)

Submission status: Accepted

Solution code:
n = int(input())
List = list(map(int,input().split()))
List = sorted(List)
a_j = List[-1]
checker = a_j
a_i = a_j
for item in List:
  temp = abs(a_j/2 - item)
  if temp < checker:
    checker = temp
    a_i = item
Answer = [a_j, a_i]
print(*Answer)

Submission status: Accepted

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

A.sort()
n = A[-1]

m = n / 2
r = 0
for i in range(N - 1):
    if abs(m - A[i]) < abs(m - r):
        r = A[i]

print(n, r)

Submission status: Accepted

Solution code:
def min_dist(n, r):
    max_arg_l = (n - 1) // 2
    max_arg_r = (n + 1) // 2

    return min(abs(max_arg_l - r), abs(max_arg_r - r))

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

    max_a = max(a)

    a = list(filter((max_a).__ne__, a))

    arg_max_a = a[0]

    for _a in a:
        if min_dist(max_a, _a) < min_dist(max_a, arg_max_a):
            arg_max_a = _a
    
    print(max_a, arg_max_a)

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
x=int(input())
y=list(map(int, input().split()))
y.sort()
chk=y[len(y)-1]
ans=0
dis=10**10
for i in range(x):
	if abs(y[i]-(chk/2))<dis:
		ans=y[i]
		dis=abs(y[i]-(chk/2))
print(chk,ans)

Submission status: Accepted

Solution code:
import bisect

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

a.sort()
m = 0
ans = []

for i in a:
    R = i / 2
    p = bisect.bisect_left(a,R)
    if p == 0:
        r = a[p]
    else:
        r = a[p] if abs(a[p] - R) < abs(a[p - 1] - R) else a[p - 1]
    if m < i + min(r,i - r):
        m = i + min(r,i - r)
        ans = [i,r]
print(*ans)

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
ma = max(A)
mid = ma / 2
l = 10000000000
f = 0
for i in range(n):
  if ((ma == A[i]) and (f==0)):
    f = 1
    continue
  if abs(l) > abs(A[i]-mid):
    l = A[i]-mid
print(ma, int(mid+l))

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

a.sort()
half = a[-1]/2

index = bisect_left(a,half)
candi1 = a[index]
if index > 0: candi0 = a[index-1]
else: candi0 = -1

if abs(half-candi0) > abs(half-candi1): ans = candi1
else: ans = candi0

print(a[-1], ans, sep=' ')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = [int(x) for x in input().split()]

a.sort()
amax = a.pop()
ans = a[0]
for i in a :
    if abs(amax/2 - ans) > abs(amax/2 - i) :
        ans = i

print(amax, ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
a1 = a[0]
a2 = a[1]
for i in range(2, n-1):
    if min(a1 - a2, a2)  < min(a1 - a[i], a[i]):
        a2 = a[i]
print(a1, a2)

Submission status: Accepted

Solution code:
# import bisect
from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    a = list(map(int,ipti().split()))
    a.sort()
    p = a[-1]
    k = 0
    min_cur = INF

    for i in range(n-1):
        temp = abs(a[i] - (p/2))
        if temp < min_cur:
            min_cur = temp
            k = a[i]

    print(p, k)





if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve():
    _ = int(input())
    a = list(map(int, input().split()))
    
    x = max(a)
    y = 0
    min_d = 10 ** 9
    if x % 2 == 0:
        for ai in a:
            if x == ai:
                continue
            d = abs(x // 2 - ai)
            if d < min_d:
                y = ai
                min_d = d
    else:
        for ai in a:
            d = min(abs(x // 2 - ai), abs(x // 2 + 1 - ai))
            if d < min_d:
                y = ai
                min_d = d
    print(x, y)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

A.sort()
ans = [0,0]
ans[0]=A[-1]
import bisect

mid = ans[0]/2
ind = bisect.bisect(A,mid)
ans[1]=A[ind-1] if mid-A[ind-1]<=A[ind]-mid else A[ind]

print(*ans)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
lmax=l[-1]
mini=abs(2*l[0]-lmax)
tmp=0
for i in range(1,n-1):
  if mini>abs(2*l[i]-lmax):
    tmp=i
    mini=abs(2*l[i]-lmax)
print(lmax,l[tmp])

Submission status: Accepted

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

a_i = max(a)
half = a_i/2

best = a_i*2
for j in a:
    if j==a_i:
        continue

    diff = abs(j-half)
    if diff < best:
        best = diff
        a_j = j

print(a_i, a_j)

Submission status: Accepted

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

a.sort()

candi = a[-1]
middle = (candi - 1) / 2

tmp = float("inf")
ans = 0

for i in range(len(a) - 1):
    if tmp >= abs(a[i] - middle):
        tmp = abs(a[i] - middle)
        ans = i
print(candi, a[ans])

Submission status: Accepted

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

combn = max(a)

ar = [abs(num-combn/2) for num in a]
if int(combn/2 - min(ar)) in a:
  combr = int(combn/2 - min(ar))
else:
  combr = int(combn/2 + min(ar))

print(' '.join(map(str,[combn,combr])))

Submission status: Accepted

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

print(M,a[ans])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
arr = list(map(int, input().split()))
ai = max(arr)
aj = 0
min_aj = float('inf')
for i in arr:
    if i == ai:
        continue
    if abs((ai - i) - i) < min_aj:
        min_aj = abs((ai - i) - i)
        aj = i
print(ai,aj)

Submission status: Accepted

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

A.sort()

ai = A[-1]

M = min(ai-A[0], A[0])
aj = A[0]

for i in range(N):
    m = min(ai-A[i], A[i])
    if M < m:
        aj = A[i]
        M = m

print(ai,aj)

Submission status: Accepted

Solution code:
n=int(input())
 
t = list(map(int,input().split()))
t.sort()
a1 = max(t)
 
ans = 100000000000000
 
memo = 0

for i in t:
    if ans > abs(a1/2-i):
        ans = abs(a1/2-i)
        memo = i
print(a1, memo)

Submission status: Accepted

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

left = a[-1]
sa = 199999999999999999999999999
for i in range(n):
  if sa > abs((left/2) -a[i]):
    right = a[i]
    sa = abs((left/2) - a[i])
    
print(left, right)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
l = a[0]
del a[0]
r = min(a,key = lambda x:abs((l/2)-x))
print(l,r)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
# B = [0] * N
n = max(A)
mid = n / 2

dic = defaultdict(int)
for i in range(N):
    dic[A[i]] = abs(A[i] - mid)
    
dic = sorted(dic.items(), key=lambda x:x[1])
k = dic[0][0]
# print(C(n, k))

# ans = (combinations_count(n, k))
print(n, k)

Submission status: Accepted

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

a.sort()

ans = (0,0)
import bisect
i = n-2
j = bisect.bisect_left(a, a[n-1]//2)
if j < n-1: i = j
if j > 0:
    if (a[n-1] - 2*a[j-1]) < (2*a[j] - a[n-1]): i = j-1

print('{} {}'.format(a[n-1], a[i]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
class cmbs(object):
    def __init__(self, mod):
        self.mod = mod
        self.g1 = [1, 1]
        self.g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, 10 ** 6 + 1):
            self.g1.append((self.g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            self.g2.append((self.g2[-1] * inverse[-1]) % mod)
    def cmb(self, n, r):
        if n > 10 ** 6:
            return self.cmbl(n, r)
        return self.cmbr(n, r)
    def cmbr(self, n, r):
        if r < 0 or r > n:
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.mod
    def cmbl(self, n, r):
        t = 1
        r = min(r, n-r)
        for i in range(n - r + 1, n + 1):
            t = t * i % self.mod
        return t * self.g2[r] % self.mod
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    x = a[-1]
    a = a[:-1]
    l = [abs(i - x/2) for i in a]
    print(x)
    print(a[l.index(min(l))])
main()

Submission status: Accepted

Solution code:
import bisect

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

a.sort()
n=a[-1]

if n%2==0:
    middleIdx=bisect.bisect_left(a[:N-1],n//2)
    
    if a[middleIdx]==n//2:
        r=a[middleIdx]
    elif a[min(middleIdx,N-2)]-n//2 > n//2-a[max(middleIdx-1,0)]:
        r=a[max(middleIdx-1,0)]
    else:
        r=a[min(middleIdx,N-2)]
    print(n,r)
else:
    m1=bisect.bisect_left(a[:N-1],n//2)
    m2=bisect.bisect_left(a[:N-1],n//2+1)
    if a[m1]==n//2:
        r=a[m1]
    elif a[m2]==n//2+1:
        r=a[m2]
    elif a[min(m2,N-2)]-(n//2+1) > n//2-a[max(m1-1,0)]:
        r=a[max(m1-1,0)]
    else:
        r=a[min(m2,N-2)]
    print(n,r)

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))
ai = a.max()

v, aj = 0, 0
for i in a:
    tmp = i * (ai - i)
    if v < tmp:
        v = tmp
        aj = i
# print(v, aj)
print(*(ai, aj))

Submission status: Accepted

Solution code:
import numpy as np

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

ai = a.max()

v, aj = 0, 0
for i in a[:-1]:
    tmp = i * (ai - i)
    if v < tmp:
        v = tmp
        aj = i
# print(v, aj)
print(ai)
print(aj)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans1 = max(a)
a.remove(ans1)
val = ans1 / 2
ans2 = int(1e10)
val2 = int(1e10)
# print(val)
for i in range(n-1):
    if abs(a[i] - val) < val2:
        ans2 = a[i]
        val2 = abs(a[i] - val)
        #print(ans2,abs(a[i] - val))
print(ans1, ans2)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
x = max(a)
half = x/2
y = sorted([ai for ai in a if ai < x], key=lambda x: abs(half-x))[0]
print("{} {}".format(x,y))

Submission status: Accepted

Solution code:
from bisect import bisect


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


x = A[-1]

A = [-float("inf")] + A[:n - 1] + [float("inf")]
i = bisect(A, x / 2)
if abs(A[i - 1] - x / 2) < abs(A[i] - x / 2):
    y = A[i - 1]
else:
    y = A[i]


print(x, y)

Submission status: Accepted

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

a.sort()

ans = 0
tmp = 10 ** 9

for i in a:
    if tmp > abs(i - a[n - 1] / 2):
        tmp = abs(i - a[n - 1] / 2)
        ans = i

print(a[n - 1], ans)

Submission status: Accepted

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

left = max(A)

right = 0
dif_min = 10**10
mid = (max(A)/2)

for i in range(n):
    if A[i] == left:
        continue
    dif = abs(A[i] - mid)
    if dif <= dif_min:
        dif_min = dif
        right = A[i]

print(str(left) + ' ' + str(right))

Submission status: Accepted

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

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

ans = [-1, 0, 0]

import bisect

i = a[-1]
idx = [bisect.bisect_left(a, i / 2), bisect.bisect_left(a, i / 2) - 1]

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

Submission status: Accepted

Solution code:
from bisect import bisect

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

x=a[-1]

if n%2==0:
  mid=x//2
else:
  mid=x//2+1

if mid in a:
  print(x,mid)
else:
  inx=bisect(a,mid)
  if a[inx]-mid>=mid-a[inx-1]:
    print(x,a[inx-1])
  else:
    print(x,a[inx])

Submission status: Accepted

Solution code:
from bisect import bisect

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

x=a[-1]
if n%2==0:
  mid=x//2
  if mid in a:
    print(x,mid)
  else:
    inx=bisect(a,mid)
    if a[inx]-mid>=mid-a[inx-1]:
      print(x,a[inx-1])
    else:
      print(x,a[inx])
else:
  mid=x//2+1
  if mid in a:
    print(x,mid)
  else:
    inx=bisect(a,mid)
    if a[inx]-mid>=mid-a[inx-1]:
      print(x,a[inx-1])
    else:
      print(x,a[inx])

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())))
ans_bigger = max(a)
ans_half = ans_bigger / 2
dif = float("inf")
for i in range(n-1):
  x = abs(a[i]-ans_half)
  if dif > x:
    dif = x
    ans_smaller = a[i]
print(ans_bigger,ans_smaller)

Submission status: Accepted

Solution code:
def main():
    from bisect import bisect_right
    n=int(input())
    num=list(map(int,input().split()))
    num.sort()
    
    i=bisect_right(num,num[-1]//2)
    if i==0:
        ans=num[0]
    else:
        if num[-1]>num[i]+num[i-1]:
            ans=num[i]
        else:
            ans=num[i-1]
    print(num[-1],ans)

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
X=A[-1]
m=X
p=A[0]
for a in A[:-1]:
  if abs(a-X/2)<m:
    m=abs(a-X/2)
    p=a
  else:
    break
print(X,p)

Submission status: Accepted

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

t=bisect.bisect_left(b,tmp)
ans=0
if(b[t]==tmp):
    ans=b[t]
elif(t==0):
    ans=b[0]
elif(t==len(b)-1):
    ans=b[-2]
else:
    c=abs(tmp-b[t-1])
    d=abs(tmp-b[t])
    if(c<=d):
        ans=b[t-1]
    else:
        ans=b[t]
print(m,ans)

Submission status: Accepted

Solution code:
n = map(int, input().split())
alist = list(map(int, input().split()))
m = max(alist)
sbn = 10**10
for a in alist:
    if abs(m/2 - a) < sbn and a != m:
        ans = a
        sbn = abs(m/2 - a)
print(m, ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect

N = int(input())
a = list(map(int,input().split()))
a.sort()
a_max = a.pop()
idx = bisect.bisect_left(a,a_max/2)
if 1 <= idx and idx != N-1:
    if a_max/2-a[idx-1] < a[idx]-a_max/2:
        idx -= 1
print(a_max,a[idx] if idx < N-1 else a[N-2])

Submission status: Accepted

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

a.sort()
an = a[-1]
a.pop()

rx = an/2
mx = rx - a[0]
r = a[0]
for i in a:
    if mx > abs(rx - i):
        mx = abs(rx - i)
        r = i

print(an, r)

Submission status: Accepted

Solution code:
import math
import numpy

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

def get_nearest(li, num):
    index = numpy.abs(numpy.asarray(li) - num).argmin()
    return li[index]

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

if n == 2:
    print(max(a), 0)
    exit()

ans_a = max(a)
ans_b = get_nearest(a, ans_a/2)

print(ans_a, ans_b)

Submission status: Accepted

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

MAX=max(a)
Harf=MAX/2

cnt=10**20
ans=0
for i in range(n):
    if MAX==a[i]:
        continue
    elif abs(Harf-a[i])<cnt:
        ans=a[i]
        cnt=abs(Harf-a[i])
print(MAX,ans)

Submission status: Accepted

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

a.sort()
num1=a[-1]

num2=-1
for i in a:
    if abs(num1/2 - i)  < abs(num1/2 - num2):
        num2=i
print(num1,num2)

Submission status: Accepted

Solution code:
from math import ceil
N = int(input())
A = list(map(int,input().split()))
ans_1 = max(A)
A.remove(ans_1)
ans_2 = 1000000
d = 10000000000
half = ceil(ans_1/2)
for e in A:
    if d > abs(half-e):
        d = abs(half-e)
        ans_2 = e
print(ans_1,ans_2)

Submission status: Accepted

Solution code:
import bisect

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

numbers.sort()
maximum = numbers[-1]

half = maximum/2
index = bisect.bisect_left(numbers, half)
if index != 0:
    if numbers[index] - half < half - numbers[index-1]:
        print('{} {}'.format(maximum, numbers[index]))
    else:
        print('{} {}'.format(maximum, numbers[index-1]))
else:
        print('{} {}'.format(maximum, numbers[0]))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
b = a[:]
bs = set(b)
f = a[-1]
for i in range(n):
    a[i] = min(a[i],f-a[i])
a.sort()
s = a[-1]
if s in bs:
    print(f,s)
    exit()
s = f - s
print(f,s)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
M, *A = sorted(map(int, input().split()), reverse=True)
if N == 2:
    print(M, *A)
    quit()
print(M, A[np.abs(np.array(A, dtype=np.int64) - M / 2).argmin()])

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
M, *A = sorted(map(int, input().split()), reverse=True)
if N == 2:
    print(M, *A)
    quit()

argmin = np.abs(np.array(A, dtype=np.int64) - M / 2).argmin()
print(M, A[argmin])

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())))
ans = a[-1]
x = ans//2
m = x-a[0]
ans2 = a[0]
for i in a[1:]:
    if i!=ans:
        z = min(i,ans-i)
        dif = x-z
        if m>dif:
            m,ans2 = dif,i
print(ans,ans2)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(map(int, input().split()))
MAX = a[-1]
mid = MAX // 2
b = float('inf')
for i in a:
    # print(mid, i, b)
    if abs(mid - i) <= b and i != MAX:
        b = mid - i
        y = i

print(MAX, y)

Submission status: Accepted

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


ans=[a[-1],a[0]]

target=a[-1]/2
d=10**9
for i in range(N-1):
    diff=abs(a[i]-target)
    if diff<d:
        d=diff
        ans[1]=a[i]

            
print(' '.join(map(str, ans)))

Submission status: Accepted

Solution code:
# coding: utf-8

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

M=max(A)
l=0
for i in range(n):
    if abs(M/2-A[i])<abs(M/2-l):
        l=A[i]
        
print(M,l)

Submission status: Accepted

Solution code:
# coding: utf-8
from math import ceil
N = int(input())
A = list(map(int, input().split()))
A.sort()
top = A[-1]
half = ceil(top / 2)
ans = float("inf")
for i in range(N):
    if abs(half - ans) > abs(half - A[i]):
        ans = A[i]
    # print(A[i], abs(half - A[i]))
print(top, ans)

Submission status: Accepted

Solution code:
#02:04
n = int(input())
a = list(map(int,input().split()))
b = max(a)
c = []
h = b/2
for i in range(n):
  c.append([abs(a[i]-h),a[i]])
d = min(c)[1]
print(b,d)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    numbers = list(map(int, input().split(" ")))
    numbers.sort()
    if numbers[-1] % 2:
        target = (numbers[-1] + 1) // 2
    else:
        target = numbers[-1] // 2
    answer = 0
    for i in range(n):
        if target <= numbers[i]:
            if i == 0:
                answer = numbers[0]
                break
            elif abs(target - numbers[i]) < abs(target - numbers[i - 1]):
                answer = numbers[i]
                break
            else:
                answer = numbers[i - 1]
                break
    print(numbers[-1], answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect
N=int(input())
A=list(map(int,input().split()))
if N==2:
  print(max(A),min(A))
else:
  B=sorted(A)
  a=B[-1]
  B=B[:N-1]
  b=bisect.bisect_left(B,a/2)
  c=abs(a/2-B[b])
  d=abs(a/2-B[b-1])
  if c>d:
    bb=B[b-1]
  else:
    bb=B[b]  
  print(a,bb)

Submission status: Accepted

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

    a.sort()
    n = a[-1]
    m = n / 2
    tmp = 10**10
    for i in a:
        if abs(m - i) < tmp:
            tmp = abs(m - i)
            r = i

    print(n, r)


if __name__ == "__main__":
    main2()

Submission status: Accepted

Solution code:
import bisect

def main():
    N = int(input())
    a = [int(i) for i in input().split()]

    a.sort()
    n = a[-1]
    m = n // 2
    right = bisect.bisect_right(a, m)

    if a[right-1] == m:
        r = m

    else:
        if n % 2 == 0:
            if m - a[right-1] <= a[right] - m:
                r = a[right-1]
            else:
                r = a[right]

        else:
            if m - a[right-1] < a[right] - (m+1):
                r = a[right-1]
            else:
                r = a[right]

    print(n, r)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a_i = max(a)
a.sort(key=lambda x: abs(a_i/2-x))

if a[0] == a_i:
    print(a_i, a[1])
else:
    print(a_i, a[0])

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
A = np.array(tuple(map(int, input().split())))
if N == 2:
    print(*A)
else:
    max_A = A.max()
    print(max_A, A[np.abs(A - max_A / 2).argmin()])

Submission status: Accepted

Solution code:
import bisect

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

a.sort()

idx = bisect.bisect_left(a,a[-1]/2)

if idx == 0:
    print(a[-1],a[idx])
else:
    x,y = a[idx-1],a[idx]
    if y - a[-1]/2 < a[-1]/2 - x:
        print(a[-1],y)
    else:
        print(a[-1],x)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
m = l.pop()
a = m
ans = 0
for r in l:
  if abs((m / 2) - r) < a:
    a = abs((m / 2) - r)
    ans = r
print(m, ans)

Submission status: Accepted

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

idx = 0
maxv = -1
for i in range(N - 1):
    if A[i] == 0:
        t = 0
    else:
        t = min(n - A[i], A[i])
    if t > maxv:
        maxv = t
        idx = i
print(n, A[idx])

Submission status: Accepted

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

m = A[-1]
res, ans = 10**9, 0

for a in A[:n-1]:
    if abs(m/2-a) < res:
        res = abs(m/2-a)
        ans = a

print(m, ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split())) # list()
a.sort(reverse = True)
hanbun = a[0]/2
sa = []

for i in range(n):
    sa.append(abs(hanbun-a[i]))

num = sa.index(min(sa))
if(num == 0):
    num = 1
'''
print(hanbun)
print(sa)
print(num)
'''
print(a[0], end=' ')
print(a[num])

Submission status: Accepted

Solution code:
N = int(input())
a = set([int(c) for c in input().split()])
a = sorted(list(a))
X = a[-1]//2+1 if a[-1]%2==1 else a[-1]//2
m = 10**9
x = 0
for i in range(N-1):
  if abs(a[i]-X)<m:
    m = abs(a[i]-X)
    x = i
print(a[-1],a[x])

Submission status: Accepted

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

def comb(a, b):
  s = 1
  for i in range(a, b, -1):
    s *= i
  return s/2
import math

MA = max(A)
A.remove(MA)
SA = sorted(A)

h = MA // 2

da = 10**10
ans = 0
for a in SA:
  diff = abs(a-h)
  if da >= diff:
    da = diff
    ans = a
print(MA, ans)

Submission status: Accepted

Solution code:
# coding: utf-8
from math import ceil
from bisect import bisect_left
N = int(input())
A = list(map(int, input().split()))
A.sort()
a = A[-1]
ans = ceil(a / 2)
b = float("inf")
for i in range(N-1):
    if abs(b - ans) > abs(A[i] - ans):
        b = A[i]
print(a, b)

Submission status: Accepted

Solution code:
# coding: utf-8
from math import ceil
from bisect import bisect_left
N = int(input())
A = list(map(int, input().split()))
A.sort()
a = A[-1]
ans = ceil(a / 2)
b = float("inf")
for i in range(N):
    if abs(b - ans) > abs(A[i] - ans):
        b = A[i]
print(a, b)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
l = max(a)
b = l / 2
r = 0
m = 10 ** 9
for i in range(n):
    if abs(a[i] - b) < m:
        m = abs(a[i] - b)
        r = a[i]

if n == 2:
    print(a[0], a[1])
else:
    print(l, r)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

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 I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    A = sorted(LI())
    n = A[-1]
    ix = bisect.bisect_left(A, n / 2)
    '''
    [1, 3, 8, 10, 12] -> bisect_left(A, 12 / 2) = 2
    [1, 2, 3, 8, 10, 12] -> bisect_left(A, 12/2) = 3
    '''
    m, l, r = inf, inf, inf
    # 最大値の半分との距離が最小のものを選ぶ
    if ix < N:
        m = A[ix]
    if 0 < ix <= N:
        l = A[ix - 1]

    m1 = abs(n / 2 - m)
    l1 = abs(n / 2 - l)

    min_val = min(m1, l1)
    if min_val == m1:
        n_ = m
    if min_val == l1:
        n_ = l

    print(n, n_)
main()

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

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 I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    A = sorted(LI())
    n = A[-1]
    ix = bisect.bisect_left(A, n / 2)
    '''
    [1, 3, 8, 10, 12] -> bisect_left(A, 12 / 2) = 2
    [1, 2, 3, 8, 10, 12] -> bisect_left(A, 12/2) = 3
    '''
    m, l, r = inf, inf, inf
    # 最大値の半分との距離が最小のものを選ぶ
    if ix < N:
        m = A[ix]
    if 0 < ix <= N:
        l = A[ix - 1]
    if ix + 1 < N:
        r = A[ix + 1]

    m1 = abs(n / 2 - m)
    l1 = abs(n / 2 - l)
    r1 = abs(n / 2 - r)

    min_val = min(m1, l1, r1)
    if min_val == m1:
        n_ = m
    if min_val == l1:
        n_ = l
    if min_val == r1:
        n_ = r

    print(n, n_)
main()

Submission status: Accepted

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

m = a[-1]
r = min(a, key = lambda x: abs((m-x)-x))
print(m, r)

Submission status: Accepted

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

m = a[-1]
r = sorted(a[:-1], key = lambda x: abs((m-x)-x))[0]
print(m, r)

Submission status: Accepted

Solution code:
import scipy.misc

N=int(input())
X=list(map(int,input().split()))
SX=sorted(X)
M=SX.pop()
MV=10**9
ANS=0
for x in SX:
  z = abs(M - x - x)
  if MV > z:
    MV = z
    ANS = x
print("{} {}".format(M,ANS))

Submission status: Accepted

Solution code:
import bisect
s = int(input())
a = list(map(int, input().split()))
aa = sorted(a)
v = 0
m = aa[-1]
x = bisect.bisect_left(aa,m//2)
if abs(aa[x-1]) > abs(m-aa[x]):
	b = aa[x-1]
else:
	b = aa[x]
if aa[x] == m:
	x -= 1
	b = aa[x]
print (m,b)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
k = max(a)
b = [0] * n
for i in range(n):
    if a[i] == k:
        b[i] = k
    else: b[i] = abs(a[i]-k/2)
r = a[b.index(min(b))]
print(k, r)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    ai = max(A)
    mi = float("inf")
    aj = 0
    for a in A:
        if ai == a:
            continue
        tmp = mi
        mi = min(mi, abs((ai - a) - a))
        if tmp != mi:
            aj = a

    print(ai, aj)

    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

a.sort(reverse=True)

n = a[0]
r = -1
t = a[0]
for aa in a[1:]:
    if abs(n/2-aa) <= t:
        r = aa
        t = abs(n/2-aa)

print(n, r)