Problem:


Score : 400 points

Problem Statement

Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order.
From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized.
If there are multiple pairs that maximize the value, any of them is accepted.

Constraints

2 \leq n \leq 10^5

0 \leq a_i \leq 10^9

a_1,a_2,...,a_n are pairwise distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

n
a_1 a_2 ... a_n

Output

Print a_i and a_j that you selected, with a space in between.

Sample Input 1

5
6 9 4 2 11

Sample Output 1

11 6

\rm{comb}(a_i,a_j) for each possible selection is as follows:

\rm{comb}(4,2)=6 

\rm{comb}(6,2)=15 

\rm{comb}(6,4)=15 

\rm{comb}(9,2)=36 

\rm{comb}(9,4)=126 

\rm{comb}(9,6)=84 

\rm{comb}(11,2)=55 

\rm{comb}(11,4)=330 

\rm{comb}(11,6)=462 

\rm{comb}(11,9)=55

Thus, we should print 11 and 6.

Sample Input 2

2
100 0

Sample Output 2

100 0



Sample input:
5
6 9 4 2 11


Sample output:
11 6

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
a1 = a.pop(0)

if a[0] <= a1 / 2:
    res = a[0]
elif a[-1] >= a1 / 2:
    res = a[-1]
else:
    left = 0
    right = n-2
    while True:
        j = (left + right) // 2
        if left == right:
            res = a[left]
            break
        elif a1/2 >= a[j+1] and a1/2 <= a[j]:
            if abs(a[j+1]-a1/2) >= abs(a[j]-a1/2):
                res = a[j]
            else:
                res = a[j+1]
            break
        elif a1/2 > a[j]:
            right = j
        else:
            left = j

print(a1, res)

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    m = max(a)
    a.remove(m)
    m2 = min(a, key=lambda x: abs(x - m / 2))
    print(m, m2)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
n = int(input())
A = list(map(int,input().split()))
A = sorted(A)
if n==2:
    cur = [A[1],A[0]]
else:
    a = A[-1]
    ind = bisect.bisect_right(A,a//2)
    b = a-A[ind]
    c = A[ind-1]
    if c>=b:
        cur = [a,c]
    else:
        cur = [a,a-b]
print(cur[0],cur[1])

Submission status: Accepted

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

seta = sorted(list(set(a)))

resn = seta[-1]
resr = seta[0]
for sa in seta:
    sabun = abs(resn / 2 - sa)
    if sabun  == 0 or sabun == 0.5:
        resr = sa
        break
    elif sabun < abs(resn / 2 - resr):
        resr = sa

print(str(resn) + " " + str(resr))

Submission status: Accepted

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

seta = sorted(list(set(a)))

resn = max(seta)
resr = seta[0]
for sa in seta:
    sabun = abs(resn / 2 - sa)
    if sabun < abs(resn / 2 - resr):
        resr = sa

print(str(resn) + " " + str(resr))

Submission status: Accepted

Solution code:
n = int(input())
a_list = sorted(list(map(int, input().split())))
 
a_i_index = len(a_list) - 1
a_i = a_list[-1]
max = 0
max_j_index = None
 
nobori = True
 
tmp = a_list[0]
koeta = None
for j_index in range(n):
    if a_list[j_index] * 2 > a_i:
        koeta = j_index
        break
    else:
        tmp = j_index
 
comb2 = 0
if n == 2:
    print(*[a_list[1], a_list[0]])
elif koeta == 0:
    print(*[a_i, a_list[koeta]])
elif (a_list[koeta]- a_i/2) > (a_i/2 - a_list[koeta-1]):
    print(*[a_i,a_list[koeta-1]])
else:
    print(*[a_i, a_list[koeta]])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
a.sort()
#print(a)
if n%2==0:
    c=a[-1]//2
else:
    c=a[-1]//2+0.5
#print(c)
b=[]
for i in range(n):
    b.append(abs(c-a[i]))
#print(b)
c=min(b)
for i in range(n):
    if b[i]==c:
        print(a[-1],a[i])
        break

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
from math import factorial
import bisect


def solve():
    N = int(input())
    As = list(map(int, input().split()))

    # ai > aj
    # C(ai, aj) とするとき、aiは大きければ大きいほどよいので、Asの最大値でよい
    # 問題はajをどう決めるか。
    """
    C(n,r) を毎回計算するのは計算が重い。なので計算させずに済む方法を考える。
    C(n,r) = n! / r!(n-r)! である。今、nはAsの最大値と決まっているので、定数とみなして良い。
    よって、C(n,r)が大きいとは、分子の r!(n-r)!ができるだけ小さいものである。
    r!(n-r)!を全探索で計算するのも処理が重いのでしたくない。
    ところで、n=10のとき、r!(n-r)!を、r = 1 ~ 10まで手書きで書いてみるとわかるが、

    1) 1* 9*8*7*6*5*4*3*2*1
    2) 1*2* 8*7*6*5*4*3*2*1
    3) 1*2*3* 7*6*5*4*3*2*1
    4) 1*2*3*4* 6*5*4*3*2*1
    5) 1*2*3*4*5* 5*4*3*2*1  <-これが一番小さい
    6) 1*2*3*4*5*6* 4*3*2*1  <-これは4)と同じ

    r = n//2のときが一番小さくなるっぽいことがわかる。

    そのようなrを、Asの中から探せば良い。これは二分探索で高速に探せる。
    """

    As.sort()
    n = As[-1]
    i = bisect.bisect_left(As[:-1], n//2)
    if i == 0:
        r = As[0]
    elif i == N-1:
        r = As[N-2]
    else:
        if abs(As[i-1] - n//2) < abs(As[i] - n//2):
            r = As[i-1]
        else:
            r = As[i]

    print(n, r)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
n=int(input())
box=sorted(list(map(int,input().split())))
right=box.pop()
point=right//2

ans=0
left=10**9
for i in box:
    if abs(i-point)<=left:
        left=abs(i-point)
        ans=i
        if ans==point or ans==point+1:
            print(right,ans)
            exit()
print(right,ans)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int, input().split()))
ans=[max(A)]

k=ans[0]
n=-1
for i in range(N):
    if abs(A[i]-ans[0]/2) < k and A[i] != ans[0]:
        k=abs(A[i]-ans[0]/2)
        n=i
ans.append(A[n])
        
print(*ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int, input().split()))
ans=[]
x=max(a)
ans.append(x)
a.remove(max(a))
y=x/2
b=10**10
d=10**10

for i in range(n-1):
    c=abs(a[i]-y)
    if b>c:
        d=a[i]
    b=min(b,c)
ans.append(d)
print(*ans)

Submission status: Accepted

Solution code:
n = int(input())
an = list(map(int, input().split()))
if n == 2:
  print(' '.join( map(str, [max(an), min(an)]) ))
  exit()

maxi = max(an)
v = maxi
for a in an:
  if a == maxi:
    continue
  if abs(a-maxi/2) < abs(v-maxi/2):
    v = a
print(' '.join( map(str, [maxi, v]) ))

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

def combination(n, r): #nCrを求める
    if n - r < r:
        r = n - r
    tmp = 1
    for i in range(n - r + 1, n + 1):
        tmp *= i
    for i in range(1, r + 1):
        tmp //= i
    return tmp
# print (a)

j = bisect_left(a, a[-1]//2)
# print (j)
tmp = abs(a[j]/a[-1] - 1/2)
ans1 = a[-1]
ans2 = a[j]
if j != 0:
    if tmp >= abs(a[j - 1]/a[-1] - 1/2):
        ans2 = a[j - 1]

print (ans1, ans2)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
mi = max(A)
an = 10000000000000
b = 0
for i in range(N):
  if an>abs(mi//2-(mi-A[i])) and A[i]!=mi:
    an = abs(mi//2-(mi-A[i]))
    b = A[i]
print(mi,b)

Submission status: Accepted

Solution code:
n=int(input())
lis=list(map(int,input().split()))
listuse=sorted(lis)
maximum=max(listuse)
if maximum%2==0:
    index=0
    for i in range(n-1):
        if abs(listuse[i]-maximum/2)>abs(listuse[i+1]-maximum/2):
            index=i+1
        else:
            index=index
    anslist=[maximum,listuse[index]]
    print(*anslist)
if maximum%2!=0:
    
    index=0
    for i in range(n-1):
        if min(abs(listuse[i]-((maximum+1)/2)),abs(listuse[i]-(maximum-1)/2))>min(abs(listuse[i+1]-((maximum+1)/2)),abs(listuse[i+1]-(maximum-1)/2)):
            index=i+1
        else:
            index=index
    anslist=[maximum,listuse[index]]
    
    print(*anslist)

Submission status: Accepted

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

A.sort()

# n, rを求める
n = A[-1]
# Nの半分にもっとも近い数を探す
standard = n/2
dif = 1e+9
r = 1e+9  # 今のrの値
for i in range(N-1):
    if abs(A[i] - standard) < dif:
        r = A[i]
        dif = abs(A[i] - standard)

print(n, r)

Submission status: Accepted

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

a.sort()
M1, M2 = 0, 0
for i in range(n) :
    m = min(a[i], a[-1] - a[i])
    if m > M2 :
        M1, M2 = a[i], m
    
print(a[-1], M1)

Submission status: Accepted

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

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

left = max(A)
center = left // 2

right = 0
diff = INF
for i in range(N):
    if A[i] == left:
        continue

    x = abs(center-A[i])
    if diff > x:
        diff = x
        right = A[i]

print(left, right)

Submission status: Accepted

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

big = -float('inf')
number = 0

for a in A:
    big = max(big, a)


ans = -float('inf')
ans_num = 0
for a in A:
    if a == big:
        continue
    number = min(a, big - a)
    if ans < number:
        ans = number
        ans_num = a
print(big, ans_num)

Submission status: Accepted

Solution code:
n = int(input())
import heapq
A = list(map(int, input().split()))
a = max(A)
b = a//2
C = []
for i in range(n):
  heapq.heappush(C, abs(A[i]-b))
c = heapq.heappop(C)
print(a)
if c+b != a and A.count(c+b) == 1:
  print(c+b)
else:
  print(b-c)

Submission status: Accepted

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

x = max(A)

num = x/2
for i in range(n):
    A[i] = [abs(A[i]-num), A[i]]
    
A.sort()
y = A[0][1]

print(x, y)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
a.sort()
ma = a.pop()
mi = -1
dif = mod
for i in range(n-1):
    if abs(ma/2-a[i]) < dif:
        mi = i
        dif = abs(ma/2-a[i])
print(ma,a[mi])

Submission status: Accepted

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

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

def solve(n: int, a: "List[int]"):
    a.sort()

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


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    solve(n, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from math import factorial
from functools import lru_cache

def fact(x: int):
    if(x == 0 or x == 1):
        return 1
    if(dp[x] != 0):
        return dp[x]
    else:
        dp[x] = x * fact(x-1)
        
    return dp[x]

# @lru_cache(maxsize=1000000000)
def comb(n: int, r: int):
    # return fact(n) // (fact(r)*fact(n-r))
    return factorial(n) // (factorial(r)*factorial(n-r))


# dp = [0] * 1000000000

def solve(n: int, a: "List[int]"):
    a.sort()

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


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    solve(n, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from math import factorial
from functools import lru_cache

def fact(x: int):
    if(x == 0 or x == 1):
        return 1
    if(dp[x] != 0):
        return dp[x]
    else:
        dp[x] = x * fact(x-1)
        
    return dp[x]

# @lru_cache(maxsize=1000000000)
def comb(n: int, r: int):
    # return fact(n) // (fact(r)*fact(n-r))
    return factorial(n) // (factorial(r)*factorial(n-r))


# dp = [0] * 1000000000

def solve(n: int, a: "List[int]"):
    a.sort()

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


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    solve(n, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
ai = max(A)
A.pop(A.index(ai))
dif = list(map(lambda a:abs(ai/2-a),A))
print(ai,A[dif.index(min(dif))])

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
ans1 = max(data)
ans2 = 0
sa = 10**9
for i in data:
    if (abs((ans1//2)-i) < sa) and (i < ans1):
        ans2 = i
        sa = abs((ans1//2)-i)
print(ans1,ans2)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
A_ = []
A_ = A[:]
A_max = max(A)

A = [abs(float(x) - float(A_max/2)) for x in A]


ans = 10**10
idx = 0
for i in range(len(A)):
    t = A[i]
    if t <= ans:
        ans = t
        idx = i

print(A_max,A_[idx])

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

from operator import itemgetter
def index_sort(A):
    x = []
    for i,a in enumerate(A):
        x.append((a,i))
    return sorted(x, key=itemgetter(0),reverse=True)

n = I()
a = III()

A = index_sort(a)
amax = A[0][0]
index = A[0][1]

temp = float('inf')
for i in range(n):
    if i==index:
        continue
    if abs(amax/2 - a[i])<abs(amax/2 - temp):
        temp = a[i]

print(amax,temp)

Submission status: Accepted

Solution code:
import heapq

n=int(input())
l=list(map(int,input().split()))
q=[10**9]

for item in l:
    heapq.heappush(q,10**9-item)

lmax=10**9-heapq.heappop(q)

sa=10**10
while True:
    a=10**9-heapq.heappop(q)
    if sa>abs(a+(-lmax//2)):
        sa=abs(a+(-lmax//2))
        ans2=a
        continue
    break

print(lmax,ans2)

Submission status: Accepted

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

x = max(a)
b1 = x//2
b2 = (x+1)//2

y = x
z = x
for i in range(len(a)):
    if a[i] != x:
        tmp = min(abs(a[i]-b1), abs(a[i]-b2))
        if tmp < y:
            z = a[i]
        y = min(tmp, y) 

ans = x*z
print(str(x) + ' '+ str(z))

Submission status: Accepted

Solution code:
N = int(input())
aList = list(map(int,input().split()))
n = max(aList)
rc = n//2
r = min(aList)
for a in aList:
    if a != n and abs(r-rc) > abs(a-rc):
        r = a
print("{} {}".format(n,r))

Submission status: Accepted

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

m, r = a[-1], 0
mid = m/2

for i in range(n-1):
    if a[i] >= mid:
        r = a[i] if abs(mid - a[i]) < abs(mid - a[i-1]) else a[i-1]
        break

print(m, r)

Submission status: Accepted

Solution code:
import bisect

n=int(input())
a=[0]+sorted(list(map(int,input().split())))+[10**9]

ans1=a[-2]

index=bisect.bisect_right(a,(ans1)//2)

b1=a[index-1]
b2=a[index]

if abs((ans1)/2-b1)<=abs((ans1)/2-b2):ans2=b1
else:ans2=b2

print(ans1,ans2,sep=" ")

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
a=list(map(int,input().split()))
i=max(a)
near=max(a)/2
j=a[np.abs(np.asarray(a)-near).argmin()]
if j==i:
    j=min(a)
print(i,j)

Submission status: Accepted

Solution code:
import math
from bisect import bisect_left

def C(a,b):
    return math.factorial(a) // (math.factorial(b)*math.factorial(a-b))

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

A = a.pop(-1)
if A//2 in a:
    print(A, A//2)
elif A % 2 != 0 and A//2 + 1 in a:
    print(A, A//2 + 1)
else:
    x = A//2
    temp = bisect_left(a, x)
    if temp == 0:
        print(A, a[0])
    elif temp == len(a):
        print(A, a[-1])
    else:
        print(A, a[sorted([temp, temp - 1], key = lambda y: abs(x - a[y]))[0]])

Submission status: Accepted

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

maximum = max(a)
others = [0] * (n)
for i in range(n):
    if a[i] != maximum:
        others[i] = min(a[i], maximum - a[i])
    else:
        others[i] = -1
choose = others.index(max(others))
ans = [maximum, a[choose]]
print(*ans)

Submission status: Accepted

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

def main():
    _ = int(input())
    A = list(map(int,input().split()))
    A.sort()
    a = A.pop()
    b = 0
    for x in A:
        if abs(a/2-x) < abs(a/2-b):
            b = x
    print(a, b)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
    _ = int(input())
    A = list(map(int,input().split()))
    A.sort()
    a = A.pop()
    bi = bisect.bisect_left(A, a//2)
    br = A[bi-1]
    if bi < len(A):
        if abs(a/2-A[bi-1]) > abs(a/2-A[bi]):
            br = A[bi]
    print(a, br)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

def comb(a,b):
  return math.factorial(a)//((math.factorial(b)*math.factorial(a-b)))

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

a.sort()
a_max=a[-1]
a=a[:-1]
#print(a)

b = [[abs(i+(-a_max//2)),i] for i in a]
b.sort()
print(a_max, b[0][1])

Submission status: Accepted

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

a_i = max(A)
a_j = a_i + 1

A.remove(a_i)
for a in A:
    if abs(a_j - a_i / 2) > abs(a - a_i / 2):
        a_j = a

print(a_i, a_j)

Submission status: Accepted

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

n = max(A)
r = A[max([(min(a,n-a),i) for i,a in enumerate(A)])[1]]

print(n,r)

Submission status: Accepted

Solution code:
# ABC094D - Binomial Coefficients (ARC095D)
def main():
    # pascal's triangle := mid area (nCn/2) is the biggest
    N, *A = map(int, open(0).read().split())
    n = max(A)
    mid, r, cur = n / 2, -1, float("inf")
    for i in A:
        if i != n:
            x = abs(mid - i)
            if x < cur:
                r, cur = i, x
    print(n, r)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
x = max(a)
a.remove(x)
ans = float("INF")
for i in range(n-1):
  if abs(ans - x/2) > abs(a[i] - x/2):
    ans = a[i]
print(x, ans)

Submission status: Accepted

Solution code:
n = int(input())
ls = list(map(int, input().split()))
m = max(ls)
ls.remove(m)
ds = [abs(x - m / 2) for x in ls]
print(m, ls[ds.index(min(ds))])

Submission status: Accepted

Solution code:
n = int(input())
ls = sorted(map(int, input().split()))
ds = [abs(x - ls[-1] / 2) for x in ls[:-1]]
print(ls[-1], ls[ds.index(min(ds))])

Submission status: Accepted

Solution code:
n = int(input())
ls = sorted(map(int, input().split()))
res = [ls[-1]]
ds = [(i, abs(x - ls[-1] / 2)) for i, x in enumerate(ls[:-1])]
ds.sort(key=lambda x: x[1])
res.append(ls[ds[0][0]])
print(*res)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
MAX = max(A)
r_A = MAX / 2
del A[A.index(MAX)]
B = list(map(lambda a:abs(a-r_A),A))
B.sort()
r1 = int(r_A + B[0])
r2 = int(r_A - B[0])
if r1 in A:
    print(MAX, r1)
else:
    print(MAX, r2)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
M = max(a)
a.remove(M)
import numpy as np
print(M,a[np.argmin([abs(i - M/2) for i in a])])

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())))
max_a = max(a)
ans = [0,10**9]
for i in a[:n-1]:
  if ans[1] > abs(max_a/2 - i):
    ans[0] = i
    ans[1] = abs(max_a/2 - i)
print(max_a,ans[0])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, = map(int, input().split())
L = [int(v) for v in input().split()]
L.sort()

ans = 0
for i in range(N):
    if ans < min(L[i], L[-1] - L[i]):
        ans = L[i]

print(L[i], ans)

Submission status: Accepted

Solution code:
import bisect


def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    a = sorted(a)
    m = a.pop(-1)
    if len(a)==1:
        left,right = 0,0
    else:
        left = bisect.bisect_left(a,m/2)
        right = max(left-1,0)
    
    if abs(m-2*a[left])<=abs(m-2*a[right]):
        print(m,end=" ")
        print(a[left])
    else:
        print(m,end=" ")
        print(a[right])
        
if __name__ == "__main__":
    main()

Submission status: Accepted

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

*else_A, max_A = sorted(A)

print(max_A, min(else_A, key=lambda a: abs(max_A/2 - a) ))

Submission status: Accepted

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

def main():
    N = int(input())
    a = list(map(int,input().split()))
    a.sort(reverse=True)
    k = max(a)
    tmp = k
    ans = 0
    for i in range(1,N):
        if tmp > abs(k//2-a[i]):
            tmp = abs(k//2-a[i])
            ans = a[i]

    print(k,ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = max(a)
a.remove(m)
p = m/2
a_m = [abs(a[i]-p) for i in range(n-1)]
print(m, a[a_m.index(min(a_m))])

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
max_a = a[-1]
temp = a[0]
for i in a[1:-1]:
    if abs(i - max_a / 2) < abs(temp - max_a / 2):
        temp = i
print(*[max_a, temp])

Submission status: Accepted

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

a.sort()

a_i = a[-1]
tmp = a_i / 2
a_j = a[0]
for j in range(n - 1):
    if abs(tmp - a[j]) < abs(tmp - a_j):
        a_j = a[j]

print(a_i, a_j)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#A
def A():
    a, b, x = LI()
    if a <= x <= a + b:
        print("YES")
    else:
        print("NO")
    return

#B
def B():
    _, m, x = LI()
    a = LI()
    print(min(bisect.bisect_left(a, x), m - bisect.bisect_right(a, x)))
    return

#C
def C():
    n = II()
    x = LI()
    xb = x[::1]
    xb.sort()
    a = xb[n // 2 - 1]
    b = xb[n // 2]
    for i in range(n):
        if x[i] <= a:
            print(b)
        elif x[i] >= b:
            print(a)
        
    return

#D
def D():
    n = II()
    a = LI()
    a.sort()
    maxa = max(a) / 2
    ans = inf
    for i in range(n):
        if abs(maxa - a[i]) < abs(maxa - ans):
            ans = a[i]
    print(max(a), ans)
    return


#Solve
if __name__ == '__main__':
    D()

Submission status: Accepted

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


if l[-1]%2 == 0:
  s = l[-1]//2
else:
  s = (l[-1]+1)//2

temp = float('inf')
for i in range(n-1):
  t = abs(l[i]-s)
  if t <= temp:
    p = l[-1]
    q = l[i]
    temp = t
print(p, q)

Submission status: Accepted

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

r = A[0]
for i in range(1, n-1):
    if abs(A[i]*2-A[-1]) < abs(r*2-A[-1]):
        r = A[i]
print(A[-1], r)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted([int(_) for _ in input().split()])[::-1]
m = a[0]
half = m/2
r = a[1]
for i in range(1, n):
    if abs(half-a[i]) < abs(half-r):
        r = a[i]

print(m, r)

Submission status: Accepted

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

a1 = A[-1]
dif = float("inf")
for i in range(N-1):
    if abs(A[i] - a1/2) < dif:
        a2 = A[i]
        dif = abs(A[i] - a1/2)

print(*[a1,a2])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 2019/09/06

from bisect import bisect_left

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

mid=mxv//2

r=bisect_left(a,mid) 
if r>=n-1:
    r=0
l=r-1 if r else 0

ans=[mxv]

if abs(mxv/2-a[r])>abs(mxv/2-a[l]):
    ans.append(a[l])
else:
    ans.append(a[r])
print(*ans)

Submission status: Accepted

Solution code:
n = int(input())
numbers =list(map(int,input().split()))
sornum =sorted(numbers, reverse=True)

ans =0
d_min = sornum[0]

for i in range(n-1):
   d =abs(sornum[0]/2-sornum[i+1])
   if d<d_min:
      d_min =d
      ans = sornum[i+1]

print('{} {}'.format(sornum[0], ans))

Submission status: Accepted

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

ax = a[-1]
az = 10 ** 9 + 1
for i in range(n-1):
  val = abs(ax/2 - a[i])
  az = min(az, val)
  #print(az, val)
  if az == val:
    ay = a[i]
  
print(ax, ay)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
ai = a[-1]
idx = bisect.bisect_left(a, ai//2)
if abs(ai//2-a[idx]) == abs(ai//2-a[idx-1]):
    if ai % 2 == 0 or idx == len(a)-1:
        print(ai, a[idx-1])
    else:
        print(ai, a[idx])
elif abs(ai//2-a[idx]) > abs(ai//2-a[idx-1]):
    print(ai, a[idx-1])
else:
    print(ai, a[idx])

Submission status: Accepted

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

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

n = max(a)

temp = n / 2
dif = 10 ** 9
r = -1
for i in a:
  if abs(temp - i) < dif:
    dif = abs(temp-i)
    r = i

print(n, r)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
m=max(a)
t=m/2
ta=10**10
c=0
for i in a:
    if i!=m:
        if abs(i-t)<ta:
            ta=abs(i-t)
            c=i
print(m,c)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    A.sort()
    maxA = A[-1]
    v = maxA / 2
    min_d = float('inf')
    min_i = None
    for i in range(n-1):
        d = abs(A[i]-v)
        if min_d > d:
            min_d = d
            min_i = i
    return  maxA, A[min_i]


if __name__ == '__main__':
    output = main()
    print(" ".join(map(str, output)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import bisect

N = int(input())

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

a.sort()



l = a[-1]
del a[-1]
a.append(float("inf"))


poi = bisect.bisect_left(a,l / 2)


if poi > 0:

    if abs(l / 2 - a[poi]) > abs(l / 2 - a[poi-1]):
        print (l,a[poi-1])
    else:
        print (l,a[poi])

else:

    print (l,a[poi])

Submission status: Accepted

Solution code:
import sys

N = int(input())
A = [int(x) for x in input().split()]
A.sort()

ma = max(A)

L = [(abs(A[i] - ma / 2), i) for i in range(N)]
lmin = min(L)

a = ma
b = A[lmin[1]]

print('{} {}'.format(a,b))

Submission status: Accepted

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


ans=a.pop(a.index(max(a)))

for i in range(n - 1):
    if a[i] > ans / 2:
        a[i] = [ans - a[i],a[i]]
    else:
        a[i] = [a[i],a[i]]
a = sorted(a,reverse = True)

print(str(ans) + " " + str(a[0][1]))

Submission status: Accepted

Solution code:
n = int(input())
As = list(map(int, input().split()))
As.sort()
m = As[-1]
k = min(As[:-1], key=lambda A: abs(m/2-A))
print(m, k)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
def nearest(array,value):
    idx = (np.abs(array-value)).argmin()
    return array[idx]
print(max(a), nearest(a[a<max(a)], max(a)//2))

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
def nearest(array,value):
    idx = (np.abs(array-value)).argmin()
    return array[idx]
print(max(a), nearest(a, max(a)//2) if n>2 else min(a))

Submission status: Accepted

Solution code:
import bisect

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

a_i = a_list.pop()

half = a_i / 2

if len(a_list) == 1:
  print(*[a_i, a_list[0]])
  exit()
  
left_index = bisect.bisect_left(a_list, half)

if left_index >= 1:
  if a_list[left_index] - half < half - a_list[left_index-1]:
    print(*[a_i, a_list[left_index]])
  else:
    print(*[a_i, a_list[left_index-1]])
if left_index == 0:
  print(*[a_i, a_list[left_index]])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ai = max(a)
diff = float("inf")
for aj in set(a):
    if abs(ai / 2 - aj) < diff:
        ans = [ai, aj]
        diff = abs(ai / 2 - aj)
print(' '.join(map(str, ans)))

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce

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


n = int(input())
a = list(map(int, input().split()))
ai = max(a)
diff = float("inf")
for aj in set(a):
    if abs(ai / 2 - aj) < diff:
        ans = [ai, aj]
        diff = abs(ai / 2 - aj)
print(' '.join(map(str, ans)))