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())
v = list(map(int,input().split()))
a = max(v)
b = 0
for i in v:
    if abs(i-a/2) < abs(b-a/2):
        b = i
print(a,b)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a_sorted = sorted(a)
i = max(a_sorted)
j = min(a_sorted, key = lambda x:abs(i - 2 * x))
print(i, j)

Submission status: Accepted

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

N = a.pop()
t = N / 2
R = a[0]
for i in a:
    R = i if abs(i-t) < abs(R-t) else R
    if i > t:
        break
print(N,R)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
alarge=a[n-1]
if a[0]>=alarge/2:
  asmall=a[0]
else:
  j=0
  while a[j]<alarge/2:
    j+=1
  if alarge<=a[j-1]+a[j]:
    asmall=a[j-1]
  else:
    asmall=a[j]
print("{} {}".format(alarge,asmall))

Submission status: Accepted

Solution code:
_ = input()

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

i = max(axs)
j = min(axs, key=lambda j: abs((i/2) - j) + (i == j))
print('{} {}'.format(i, j))

Submission status: Accepted

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

max_n = max(a)
a.remove(max_n)

half = max_n/2
tmp = float("inf")
result = 0
for i in a:
    if tmp > abs(half-i):
        tmp = abs(half-i)
        result = i
print(max_n, result)

Submission status: Accepted

Solution code:
_ = input()

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

i = max(axs)
j = min(axs, key=lambda j: abs((i/2) - j) + (i == j))
print('{} {}'.format(i, j))

Submission status: Accepted

Solution code:
from math import factorial

n = int(input())
a = list(map(int, input().split()))
max_a = max(a)
a.remove(max_a)
dis = float('inf')
ans = 0
for a_i in a:
    if abs(a_i - max_a//2) < dis:
        ans = a_i
        dis = abs(a_i - max_a//2)

print(max_a, ans)

Submission status: Accepted

Solution code:
N = int(input())

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

a = max(X)

b = a/2
t = min([i for i in X if i>=b])
s = max([i for i in X if i<=b])
if t-b >= b-s:
  print(a,s)
elif t-b < b-s:
  print(a,t)

Submission status: Accepted

Solution code:
import sys
N = int(input())
A =[int(i) for i in input().split()]
a = max(A)
if a%2==0:
    seco=0
    s =a//2
    for i in A:
        if i <=s:
            seco=max(seco,i)
        else:
            seco=max(seco,a-i)
else:
    seco=0
    s = a//2 +1
    for i in A:
        if i <=s:
            seco=max(seco,i)
        else:
            seco=max(seco,a-i)

for i in A:
    if i==seco:
        print(a,seco)
        sys.exit()
print(a,a-seco)

Submission status: Accepted

Solution code:
import bisect

n = int(input())
A = list(map(int, input().split()))
A.sort()
if len(A) == 2:
    print(A[1], A[0])
    exit()
m = A[-1]
xr = bisect.bisect(A, m/2)
LR = A[xr-1:xr+1]
r = LR[1] if m/2 - LR[0] > LR[1] - m/2 else LR[0]
print(m, r)

Submission status: Accepted

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


# iを探す
a_array = numpy.asarray(a)
n_i = a_array.argmax()

n_ret= a_array[n_i]

a_array2 = numpy.delete(a_array, n_i)



n_want_r = n_ret / 2

r_i = numpy.abs(a_array2 - n_want_r).argmin()

print("{} {}".format(n_ret, a_array2[r_i] ))

Submission status: Accepted

Solution code:

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

I=A[N-1]

motometai=I/2

J=10**10

for i in range(N-1):
    if abs(I/2- A[i])<abs(I/2-J):
        J=A[i]
    

        


print(I,J)

Submission status: Accepted

Solution code:
import bisect
import sys
import math

n = int(input())
array = sorted([int(x) for x in input().split()])
if n == 2:
    print(array[1], array[0])
    sys.exit()

half = math.ceil(array[-1]/2)
pos = bisect.bisect_left(array, half)
_dict = {}
_dict[abs(half - array[pos])] = array[pos]
_dict[abs(half - array[pos-1])] = array[pos-1]
_dict[abs(half - array[pos+1])] = array[pos+1]

res = _dict[min(_dict.keys())]
print(array[-1], res)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
m=max(a)
m2 = m / 2

f = m
ans = -m
for i in a:
  if i != m and abs(m2 - i) <=f:
    f = abs(m2 - i)
    ans = i
print(m,ans)

Submission status: Accepted

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

if len(a) == 1:
    result = list(a)[0]
    print("{} {}".format(result, result))

x = max(a)
result = min(a)
for i in sorted(a):
    if i == (x // 2):
        result = i
        break
    elif i < x / 2:
        result = i
    elif (i - x / 2) < (x / 2 - result):
        result = i
        break
    else:
        break

print("{} {}".format(x, result))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
max_a = max(a)
a.remove(max_a)
min_diff = 1000000000
for a_i in a:
    if min_diff > abs(max_a / 2 - a_i):
        min_diff = abs(max_a / 2 - a_i)
        half_a = a_i
print(max_a, half_a)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ansm=max(a)
a.remove(ansm)
h=ansm//2
absmin=10**9


ans=a[0]
for x in a:
    if abs(x-h)<absmin:
        ans,absmin=x,abs(x-h)
print(ansm,ans)

Submission status: Accepted

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

a_i = max(a)
a_j = 0
min_d = float('inf')
for a_k in a:
    if a_k == a_i:
        continue
    d = abs(a_i / 2 - a_k)
    if d < min_d:
        min_d = d
        a_j = a_k
print(a_i, a_j)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# kakomon toku
import math
import sys
import itertools
import numpy as np
 
n = int(input())
a = [int(i) for i in input().split()]
 
#print(a)
a = np.sort(a)
ai = a[n-1]
aj = a[0]
center = ai / 2
diff = ai
i=0
for m in a:
    if diff > abs(m - center) :
        aj = m
        diff = abs(aj - center)
    else:
        break
 
print(ai,aj)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
a = sorted(a)
sai = max(a)
ma = 100000000000000000000000000
naka = sai / 2
for i in range(N):
    sa = abs(naka - a[i])
    if ma > sa:
       ma = sa
       kore = a[i]
print(sai,kore)

Submission status: Accepted

Solution code:
n = int(input())
a_n = list(map(int, input().split()))
result1 = max(a_n)
min_delta = max(a_n)
result2 = max(a_n)
for num in a_n:
    if num == result1:
        pass
    elif abs(num-result1/2)<=min_delta:
        min_delta = abs(num-result1/2)
        result2 = num
print('{} {}'.format(result1, result2))

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
l.sort()
a = l[-1]
j = 0
while l[j] < int((a+1)/2):
    j += 1
else:
    if l[j] - int((a+1)/2) < int((a+1)/2) - l[j-1]:
        b = l[j]
    else:
        b = l[j-1]
print("{} {}".format(a,b))

Submission status: Accepted

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
A_max = max(A)
A.remove(A_max)
A_sub = [abs(A_max-i*2) for i in A]
print(A_max, A[A_sub.index(min(A_sub))])

Submission status: Accepted

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
A_max = max(A)
A.remove(A_max)
print(A_max, min(A, key=lambda x:abs(A_max-x*2)))

Submission status: Accepted

Solution code:
n = int(input())
A = sorted([int(i) for i in input().split()])
A_max = A.pop()
print(A_max, min(A, key=lambda x:abs(A_max-x*2)))

Submission status: Accepted

Solution code:
n = int(input())
A = sorted(list(map(int, input().split())))
A_max = A.pop()
n = A_max/2
n = min([(abs(n-i), i) for i in A], key=lambda x:x[0])[1]
print(A_max, n)

Submission status: Accepted

Solution code:
N = int(input())
list = list(map(int,input().split()))
#print(list)
sa_list = []
ai = max(list)
for i in range(N):
    sa2 = abs(( list[i] - ai/2 ) *2)
    
   #print(sa)
    sa_list.append(int(sa2))
#print(sa_list)
basyo = (sa_list.index(min(sa_list)))
ar = list[basyo]
if ai == ar:
    print(str(ai) + " " + str(ai - ar))
else:
    print(str(ai) + " " + str(ar))

Submission status: Accepted

Solution code:
from bisect import bisect_left

N = int(input())
data = list(map(int, input().split(' ')))
sorteddata = sorted(data)

def takeClosest(myList, myNumber):
    pos = bisect_left(myList, myNumber)
    if pos == 0:
        return myList[0]
    if pos == len(myList):
        return myList[-1]
    before = myList[pos - 1]
    after = myList[pos]
    if after - myNumber < myNumber - before:
       return after
    else:
       return before

ans = takeClosest(sorteddata, sorteddata[-1] / 2)
print(str(sorteddata[-1]) + ' ' + str(ans))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = max(a)
mi = 0
I = 0
for i in a:
    if(min([i, m - i]) >= mi):
        mi = min([i, m - i])
        I = i
print(m, I)

Submission status: Accepted

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

max = max(a)
a1 = a[:]
del a1[a.index(max)]
b = [abs( max/2 - a1[i]) for i in range(n-1)]

minb = min(b)
index = b.index(minb)

print(max, end = ' ')
print(a1[index])

Submission status: Accepted

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

x.sort()
mx = x[n-1]
print(mx," ",sep="",end="")
i = 1
while True:
    if x[i] - mx/2 >= 0:
        break
    i += 1
if mx/2 - x[i-1] <= x[i] - mx/2:
    print(x[i-1])
else:
    print(x[i])

Submission status: Accepted

Solution code:
def read():
    return int(input())


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


def readmap():
    return map(int, input().split())


N = read()
A = readlist()

n = max(A)

mi = 999999999999999999999
for a in A:
    if n != a:
        if abs(a - n/2) < mi:
            b = a
            mi = abs(a - n/2)

print(n, b)

Submission status: Accepted

Solution code:
n = input()
a = sorted(map(int, raw_input().split()))
a_i = a[-1]
a_j = a[0]
best = -1
for j in range(n-1):
    cur = min(a_i - a[j], a[j])
    if best < cur:
        a_j = a[j]
        best = cur
print "%d %d" % (a_i, a_j)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# kakomon toku
import math
import sys
import itertools
import numpy as np

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

#print(a)
a = np.sort(a)
ai = a[n-1]
aj = a[0]
center = ai / 2
diff = ai
i=0
for m in a:
    if diff > abs(m - center) :
        aj = m
        diff = abs(aj - center)
    else:
        break

print(ai,aj)

Submission status: Accepted

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

a = sorted(a)
r = a[0]
diff = abs(a[-1] - a[0] * 2)
for num in a:
    diff2 = abs(a[-1] - num * 2)
    if diff2 < diff:
        diff = diff2
        r = num

print("{} {}".format(a[-1], r))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# kakomon toku
import math
import sys
import itertools
import numpy as np

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

#print(a)
ai=0
for m in a:
    if ai < m:
        ai = m
a = np.sort(a)
aj = a[0]
center = ai / 2
diff = ai
i=0
for m in a:
    if diff > abs(m - center) :
        aj = m
        diff = abs(aj - center)
    else:
        break

print(ai,aj)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# kakomon toku
import math
import sys
import itertools
import numpy as np

n = int(input())
a = [int(i) for i in input().split()]
#print(a)
ai=0
for i in range(n):
    if ai < a[i]:
        ai = a[i]
a = np.sort(a)
aj = a[0]
center = ai / 2
diff = ai
i=0
for i in range(n):
    if diff > abs(a[i] - center) :
        aj = a[i]
        diff = abs(aj - center)
    else:
        break

print(ai,aj)

Submission status: Accepted

Solution code:
N = int(input())
As = input().split()
As = [int(A) for A in As]
Ai = max(As)
x = float('inf')
for a in As:
    if abs((Ai - a) - a) <= x:
        x = abs((Ai - a) - a)
        Aj = a
print(Ai, Aj)

Submission status: Accepted

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
M=max(A)
S=10**9
j=0
for i in range(N):
  if S>=abs(2*A[i]-M):
    j=i
    S=abs(2*A[j]-M)
print(M,A[j])

Submission status: Accepted

Solution code:
N=int(input())
X=[int(i) for i in input().split()]
M=max(X)
S=10**10
j=0
for i in range(N):
  if abs(2*X[i]-M)<=S:
    j=i
    S=abs(2*X[i]-M)
print(M,X[j])

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ai=max(a)
a2=sorted(a,key=lambda x:abs(ai/2-x))
aj = a2[0] if a2[0] != ai else a2[1]
print("{} {}".format(ai,aj))

Submission status: Accepted

Solution code:
N=int(input())
s=list(map(int,input().split()))
n=max(s)
s.remove(n)
q=n
for i in s:
    t=abs(n/2-i)
    if q>=t:
        q=t
        w=str(n)+" "+str(i)
print(w)

Submission status: Accepted

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


N = max(As)
Bs = [(abs(a - N / 2), a) for a in As]
_, r = min(Bs)
print(N, r)

Submission status: Accepted

Solution code:
import bisect as bs
n = int(input())
a = sorted(list(map(int,input().split())))
max = a[len(a)-1]
idx  = bs.bisect_left(a,int(max/2))
if idx != 0 and max/2.0-a[idx-1] <= a[idx]-max/2.0:
    idx = idx-1
print(max,a[idx])

Submission status: Accepted

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

Submission status: Accepted

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

a_max = max(a)

a2 = a_max
for i in a:
    if  a2 >= abs(i - a_max/2):
        a2 = abs(i - a_max/2)
        r = i

print(a_max, r)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
x,a = a[-1],a[:-1]
temp = []
for i in a:
    temp.append(abs(x/2-i))
y=a[temp.index(min(temp))]
print(x,y)

Submission status: Accepted

Solution code:
# coding:utf-8

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

MAX = 0
n = a.pop(0)
b = [abs(i - n / 2) for i in a]
r = a[b.index(min(b))]
print(n, r)

Submission status: Accepted

Solution code:
def comb(x, y):
    return math.factorial(x) / (math.factorial(x - y) * math.factorial(y))

def solve(N, AS):
    x = max(AS)
    AS = list(AS)
    AS.remove(x)
    y = min(map(lambda z: [abs(z - x / 2), z] , AS), key=lambda x: x[0])[1]
    return (x, y)

if __name__ == '__main__':
    n = int(input())
    AS  = list(map(lambda x: int(x), input().split()))
    tmp = solve(n, AS)
    print(tmp[0], tmp[1])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = sorted(a)
maxb = max(b)
mini = b[0]
for i in b:
    if abs(maxb/2 - i) < abs(maxb/2 - mini):
        mini = i
print(maxb,mini)

Submission status: Accepted

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

import bisect

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

if abs(a[n-1] / 2 - a[arg_max_i]) > abs(a[n-1] / 2 - a[arg_max_i-1]):
  arg_max_i -= 1
if arg_max_i == n-1:
  arg_max_i -= 1

print(a[n-1], a[arg_max_i])

Submission status: Accepted

Solution code:
def main():
    """
    nCr の最大化
    2 <= n <= 10^5
        全組合せでは間に合わない
        sortして必要なものを選ぶ
    0 <= ai <= 10^9
        実際に場合の数を求めていては間に合わない
        階乗でO(N)は時間がかかる+数が大きくて処理時間が長い

    nCr = nPr / r!
        nが大きいほど大きい
        rが大きいほど大きい?
    nCr: 7C4 = 7C3
        if r > n // 2
            7C3: 7*6+5 / 3*2
            7C2: 7*6   /   2
        n-r が大きいほど大きい
    """
    n = int(input())
    *a, = map(int, input().split())

    a = sorted(a)
    m = a[-1]
    m2 = m // 2
    r, r_tmp = 0, 0
    for _a in a:
        tmp = _a
        if _a > m2:
            tmp = m - _a
        
        if tmp > r_tmp:
            r = _a
            r_tmp = tmp

    print(m, r)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
D - Binomial Coefficients
https://beta.atcoder.jp/contests/abc094/tasks/arc095_b

"""
import sys
from sys import stdin
input = stdin.readline


def solve(A):
    A.sort()
    large = A[-1]
    small = A[0]
    target = large / 2.0
    gap = large - small

    for a in A[1:-1]:
        t = abs(target - a)
        if t < gap:
            gap = t
            small = a
    return large, small


def main(args):
    n = int(input())
    A = [int(x) for x in input().split()]
    l, s = solve(A)
    print(l, s)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

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

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

b=[(a[i],abs(x/2-a[i])) for i in range(n)]

b.sort(key=lambda x:x[1])
print(x,b[0][0])

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
i = a[-1]
j = min(a, key=lambda x:abs(i - x * 2))
print(i, j)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
m = max(a)
print(m,min(a,key=lambda x:abs(m-x*2)))

Submission status: Accepted

Solution code:
n = int(input())
a = input().split(" ")
for i in range(n):
    a[i] = int(a[i])
a.sort()
ans_bef = max(a)
ans_aft = a[0]
med = ans_bef/2
for i in range(1, n-1):
    if abs(med-a[i]) < abs(med-ans_aft):
        ans_aft = a[i]
print(ans_bef, ans_aft)

Submission status: Accepted

Solution code:
input()
arr=sorted(int(x)for x in input().split())
m=arr[-1]
print(m,min(arr,key=lambda x:abs(m-x*2)))

Submission status: Accepted

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

def comb(n, r):
    result = 1
    for i in range(r):
        result = int(result * (n - i) / (i + 1))

    return result

# Nを取得
n = int(input())

# Aiを取得
a_list = list(map(int, input().split()))

# 昇順にソートしたAiを取得
a_sorted = sorted(a_list)

# 最大値およびその1/2の値を取得
a_max = max(a_sorted)

# comb(n,r)が最大になるrを取得
r = 0
d_min = a_max + 1
for a in a_sorted:
    d = abs(a_max - (2 * a))
    if d < d_min:
        d_min = d
        r = a
    else:
        break

# c = comb(a_max, r)

# 結果を出力
print("{} {}".format(a_max, r))

Submission status: Accepted

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

b=a[:]
c=a[-1]

#print('c',c)


for i in range(len(a)):
    a[i]=abs(a[i]-int((c+1)/2))

#for j in range(len(a)):
#    print(a[j])


ans = b[a.index(min(a))]

#print('ans',ans)


print(b[-1],ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ai = max(a)
aj = min(filter(lambda x: x!=ai, a), key=lambda x: abs(x-ai//2))
print("{} {}".format(ai, aj))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ai = max(a)
aj = min((item for item in a if item != ai), key=lambda x: abs(x-ai//2))
print("{} {}".format(ai, aj))

Submission status: Accepted

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

a = sorted(a)

r = 0
minV = 10**10
for i in range(n-1):
	curr = abs(a[-1] / 2 - a[i])
#	print(a[-1],a[i],curr)
	if minV > curr:
		r = a[i]
		minV = curr

print(a[-1], r)

Submission status: Accepted

Solution code:
#abc094d
 
n=int(raw_input())
a=map(int,raw_input().split())
x=max(a)
if x%2:
 m=(x+1)/2
else:
 m=x/2
d=[]
for i in xrange(n):
 d.append(abs(a[i]-m))
y=min(d)
z=d.index(y)
u=a[z]
if n==2:
 x=a[0]
 u=a[1]
print x,u

Submission status: Accepted

Solution code:
def someone_ans():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    x_max = a[n - 1]
    center = a[0]
    for i in range(1, n - 1):
        if abs(center - x_max / 2) > abs(a[i] - x_max / 2):
            center = a[i]
    return "{0} {1}".format(x_max, center)


print(someone_ans())

Submission status: Accepted

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
a_list.sort()
max_num = max(a_list)
a_list.pop()
n_half = max_num / 2
a_list_dif = [abs(i - n_half) for i in a_list]
min_idx = 0
min_val = 10 ** 10
for idx, v in enumerate(a_list_dif):
    if v < min_val:
        min_idx = idx
        min_val = v
print(max_num, a_list[min_idx])

Submission status: Accepted

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
a_list.sort()
max_num = max(a_list)
a_list.pop()
n_half = max_num / 2
a_list_dif = [abs(i - n_half) for i in a_list]
dif_min_num = min(a_list_dif)
r = 0
if n_half + dif_min_num in a_list:
    r = int(n_half + dif_min_num)
elif n_half - dif_min_num in a_list:
    r = int(n_half - dif_min_num)
else:
    r = 0
print(max_num, r)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
p = max(A)
q = p//2
r = 10**9+7
ans = 0
for k in range(N):
    if abs(A[k]-q) < r and A[k] != p:
        r = abs(A[k]-q)
        ans = A[k]

print(p,ans)

Submission status: Accepted

Solution code:
import copy

n = int(input())
x = list(map(int, input().split()))
x_sort = copy.deepcopy(x)
x_sort.sort()

x_max = x_sort[n - 1]
center = x_sort[0]
for i in range(1, n - 1):
    if abs(center - x_max / 2) > abs(x_sort[i] - x_max / 2):
        center = x_sort[i]

print(x_max, center)

Submission status: Accepted

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

a.sort()

min = a[-1]/2
r = a[0]
for item in a[:-1]:
    if abs(item - a[-1]/2) < min:
        min = abs(item - a[-1]/2)
        r = item
print(a[-1], r)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
m = max(A) 
min = float("inf")
for i in range(n):
  if min > abs(A[i] - m/2) and A[i] != m: 
    min = abs(A[i] - m/2)
    r = A[i]
print(m,r)

Submission status: Accepted

Solution code:
import sys
import numpy
import math

N=int(input())

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

dekaiyatu=numpy.argmax(A)
kati=A[dekaiyatu]

A.pop(dekaiyatu)
iikanjinoyatu= numpy.argmin(list(map((lambda x: abs((kati/2)-x)), A)))
string=str(kati)+" "+str(A[iikanjinoyatu])

print(string)

Submission status: Accepted

Solution code:
def bin_search(x,v):
    if x<=v[0]:
        return v[0]
    elif x>=v[-1]: return v[-1]
    l = 0
    r = len(v)
    while l+1<=r:
        i = (l+r)//2
        if v[i]<=x and x<=v[i+1]:
            if x-v[i] >= v[i+1]-x:
                return v[i+1]
            else: return v[i]
        elif v[i]>x: r=i
        else: l=i
    return False

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

print(v[-1],bin_search(v[-1]/2,v[:-1]))

Submission status: Accepted

Solution code:
import numpy as np

n = int(input().strip())
A = list(map(int,input().strip().split(' ')))
sorted_A = sorted(A)
ai=sorted_A[-1]
print(ai)
del sorted_A[-1]
tmplist=np.array([min(i,ai-i) for i in sorted_A])
maxidx = np.argmax(tmplist)

print(sorted_A[int(maxidx)])

Submission status: Accepted

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

r = max(a)
Len = abs(a[0] - r/2)
l = a[0]
for i in range(n):
    if abs(a[i] - r/2) <= Len:
        Len = abs(a[i] - r/2)
        l = a[i]

print("%d %d" % (r, l))

Submission status: Accepted

Solution code:
#coding:utf-8                                              
import numpy as np                                         
                                                           
n = int(input())                                           
comb_list = [int(i) for i in input().split()]              
                                                           
max_num = max(comb_list)                                   
idx = np.abs(np.asarray(comb_list) - max_num / 2).argmin() 
ans = comb_list[idx]                                       
if ans == max_num:                                         
  ans = 0                                                  
                                                           
print(max_num, ans)

Submission status: Accepted

Solution code:
import bisect
import math
n =  int(input().strip())
nums  = list(map(int, input().strip().split(' ')))
sortedNums = sorted(nums)
x = sortedNums[-1]
insert_index  = bisect.bisect_left(sortedNums,int(x/2))
if insert_index == 0: y = sortedNums[0]
else:
    if x/2 - sortedNums[insert_index-1] > sortedNums[insert_index]-x/2: y = sortedNums[insert_index]
    else: y = sortedNums[insert_index - 1]
if n==2: y=sortedNums[0]
print(x,y)

Submission status: Accepted

Solution code:
import sys

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    a_sorted = sorted(a)
    distance = sys.maxsize
    r = -1
    for i in a:
        if abs(i - a_sorted[n-1]/2) <= distance:
            distance = abs(i - a_sorted[n-1]/2)
            r = i
    print(str(a_sorted[n-1]) + ' ' + str(r))

Submission status: Accepted

Solution code:
n = int(input())
an = [int(i) for i in input().split()]
an.sort()
ai = an[-1]
print("%d %d"%(ai, min(an, key=lambda i:abs(ai-i*2))))

Submission status: Accepted

Solution code:
from bisect import bisect_left
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
x = a[-1]
b = (x+1)*1.0/2
num = bisect_left(a,int(b))
if num==0: y = a[0]
else:
	if b-a[num-1] > a[num]-b: y = a[num]
	else: y = a[num-1]
if n==2: y=a[0]
print(x,y)

Submission status: Accepted

Solution code:
n = int(input())
l = sorted(list(map(int, input().split())))
base = l[-1]
ans = 0
if base % 2 == 0:
  half = base //2
else:
  half = base // 2 + 1

diff = float('Inf')
for i in l:
  if abs(half-i) < diff:
    diff = abs(half-i)
    ans = i

print(base, ans)

Submission status: Accepted

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

a.sort()
a.reverse()
max = 0

for i in range(1, n):
  m = min(a[0] - a[i], a[i])
  #c = comb(a[0], a[i])
  if m > max:
    max = m
  else:
    i -= 1
    break

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

Submission status: Accepted

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


mid=a[N]
resu=[0,N,n-2]
while resu[2]-resu[0]>1:
    if mid-max_a/2>0:
        resu[2]=N
        N=int((resu[0]+resu[1])/2)
        resu[1]=N
        mid=a[N]
    elif mid==max_a/2:
        break
    else:
        resu[0]=N
        N=int((resu[1]+resu[2])/2)
        resu[1]=N
        mid=a[N]
if resu[2]-resu[0]==1:
    if a[resu[0]]+a[resu[2]]-max_a>0:
        resu[1]=resu[0]
    else:
        resu[1]=resu[2]
       
print(max_a,a[resu[1]])

Submission status: Accepted

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

n = int(input())
a = list(map(int, input().split()))
a_max = max(a)
half_max = a_max / 2
tmp = [abs(half_max - v) for v in a]
b = a[tmp.index(min(tmp))]
if b == a_max and 0 in a:
    print("{} 0".format(a_max))
else:
    print("{} {}".format(a_max, b))

Submission status: Accepted

Solution code:
n = int(input())
aa = list(map(int,input().split()))
ma = max(aa)
ans = 0

if len(aa) == 2:
 print(ma,min(aa))
else:
 if ma % 2 == 0:
  for a in aa:
   if abs(ma//2 - a) <= abs(ma//2 - ans):
    ans = a
 else:
  for a in aa:
   if min([abs(ma // 2 - a),abs(ma //2 - a + 1)  ]) <= min([abs(ma // 2 - ans),abs(ma //2 - ans + 1)  ]):
    ans = a
 print( "{} {}".format(ma,ans))

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem D

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    a_max = max(a)
    a.remove(a_max)
    a = sorted(a)

    # See:
    # https://www.youtube.com/watch?v=RwWljbtCrPA
    # https://img.atcoder.jp/arc095/editorial.pdf
    # https://beta.atcoder.jp/contests/abc094/submissions/2354745
    k = [abs(a_max / 2 - ai) for ai in a]
    center = k.index(min(k))
    print(a_max, a[center])

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem D

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    a_max = max(a)
    a.remove(a_max)
    a = sorted(a)

    # See:
    # https://www.youtube.com/watch?v=RwWljbtCrPA
    # https://img.atcoder.jp/arc095/editorial.pdf
    diff = float('inf')
    center = 0

    for ai in a:
        current_diff = abs(a_max / 2 - ai)

        if current_diff < diff:
            diff = current_diff
            center = ai

    print(str(a_max) + ' ' + str(center))

Submission status: Accepted

Solution code:
N = int(input())
X = [int(d) for d in input().split()]

max_ = max(X)
X.remove(max_)

center = max_/2
abs_ = float('inf')
t_index = None


for i in range(N-1):
	if abs(center - X[i]) < abs_:
		abs_ = abs(center - X[i])
		t_index = i

print(max_,X[t_index])

Submission status: Accepted

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

maximal=max(A)
print(maximal,end=" ")
B=list(map(lambda x:abs(x - maximal/2),A))
minimam=B.index(min(B))
if A[minimam]==maximal:
    print("0")
else:
    print(A[minimam])

Submission status: Accepted

Solution code:
INF = 1000000000000000
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
ai = a[n - 1]
aj = -1
center = ai / 2
margin = INF
for i in range(n):
    if margin > abs(center - a[i]):
        aj = a[i]
        margin = abs(center - a[i])
print(ai, aj)

Submission status: Accepted

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

k=(enu)/2
sa=float("inf")
 
for i in range(n-1):
    if abs(k-a[i])<sa:
        sa=abs(k-a[i])
        aru=a[i]
 
print(enu,aru)

Submission status: Accepted

Solution code:
import bisect

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

nnn=a[n-1]
k=bisect.bisect_left(a[:n-1], nnn/2)
  
if k==n-1:
  rrr=a[n-2]
else:
  if abs(a[k-1]-nnn/2) < abs(a[k]-nnn/2):
    rrr=a[k-1]
  else:
    rrr=a[k]

print(nnn, rrr)

Submission status: Accepted

Solution code:
n=int(input())
A=[int(i) for i in input().split()]
n_output=max(A)
mean=n_output/2
r=10000000000
r_output=10000000000
for i in range (n):
    if abs(A[i]-mean)<=r:
        r=abs(A[i]-mean)
        r_output=A[i]
list=[]
list.append(n_output)
list.append(r_output)
list.sort()
list.reverse()
print(list[0],list[1])

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
 
enu=max(a)
 
k=(enu)/2
sa=float("inf")
 
for i in range(n):
    if abs(k-a[i])<sa and a[i]!=enu:
        sa=abs(k-a[i])
        aru=a[i]
 
print(enu,aru)

Submission status: Accepted

Solution code:
n = input()
a = sorted(int(x) for x in input().split())
max_a = a[-1]
print(max_a, min(a, key=lambda x: abs(max_a - x * 2)))