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:
from sys import stdin
import bisect

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

li.sort()

a = li.pop()
if len(li) == 1:
    print(a,li[0])
else:
    bi = bisect.bisect_left(li,a/2)
    b = li[bi]
    if bi != 0:
        c = li[bi-1]
        if abs(a/2-c) <= abs(a/2-b):
            print(a,c)
        else:
            print(a,b)
    else:
        print(a,b)

Submission status: Accepted

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

import bisect
i=-1
bunshi=A[i]
target=A[i]/2
tarp=bisect.bisect_left(A,target)
diff=10**9+1
if tarp-1>=0:
  diff=abs(target-A[tarp-1])
if abs(target-A[tarp])<diff:
  print(bunshi,A[tarp])
else:
  print(bunshi,A[tarp-1])

Submission status: Accepted

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

import bisect
maxval=0
maxpair=None

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

i=-1
bunshi=A[i]
target=A[i]/2
tarp=bisect.bisect_left(A,target)
diff=10**9+1
if tarp-1>=0:
  diff=abs(target-A[tarp-1])
if abs(target-A[tarp])<diff:
  print(bunshi,A[tarp])
else:
  print(bunshi,A[tarp-1])

Submission status: Accepted

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

ai = max(a)
if ai % 2 == 0:
    mid = [ai // 2]
else:
    mid = [ai // 2, ai // 2 + 1]

mini = float('INF')
minia = 0
for aa in a:
    if aa <= mid[0]:
        t = mid[0]-aa
        minia = aa
    else:
        t = aa-mid[-1]
    if t < mini:
        mini = t
        minia = aa
print(ai, minia)

Submission status: Accepted

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

def solve(n: int, a: "List[int]"):
    if n == 2:
        print(*sorted(a,reverse=True))
        return 

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


    if max_a%2 ==1:
        searchValue = max_a//2+1
    else:
        searchValue = max_a//2

    index = bisect.bisect_left(a,searchValue)
    if abs(max_a/2-a[index]) > abs(max_a/2-a[index-1]):
        print(max_a,a[index-1])
    else:
        print(max_a,a[index])

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    solve(n, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# nCr的にn//2に近いほうがいいに決まっている
# まあnCrは計算しなくていい

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


def lower_bound(arr, t):
    l, r = 0, len(arr)
    while l < r:
        mid = (l + r) // 2
        if arr[mid] < t:
            l = mid + 1
        else:
            r = mid
    return l


lb = lower_bound(arr[:-2], round(arr[-1] / 2))
lb_left = max(0, lb - 1)
if abs(round(arr[-1] / 2) - arr[lb]) >= abs(round(arr[-1] / 2) - arr[lb_left]):
    print(arr[-1], arr[lb_left])
else:
    print(arr[-1], arr[lb])

Submission status: Accepted

Solution code:
def main():
    _ = int(input())
    A = [int(i) for i in input().split()]
    max_A = max(A)
    idx = A.index(max_A)
    diff = 1 << 60
    ans = 0
    if max_A % 2 == 0:
        for i, a in enumerate(A):
            if i == idx:
                continue
            if abs(max_A//2 - a) < diff:
                diff = abs(max_A//2 - a)
                ans = a
    else:
        for i, a in enumerate(A):
            if i == idx:
                continue
            if abs(max_A//2-a) < diff:
                diff = abs(max_A//2 - a)
                ans = a
            elif abs((max_A//2)+1 - a) < diff:
                diff = abs((max_A//2)+1 - a)
                ans = a

    print(max_A, ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def examD():
    N = I()
    A = LI(); A.sort()
    ans = [max(A)]
    ansC = ans[0]/2
    lower = 0; upper = N-2
    while(upper-lower>1):
        now = (lower+upper)//2
        if A[now]>ansC:
            upper = now
        elif A[now]<ansC:
            lower = now
        else:
            ans.append(int(ansC))
            break
    if len(ans)==1:
        if abs(A[upper]-ansC)-abs(A[lower]-ansC)<0:
            now = upper
        else:
            now = lower
        ans.append(A[int(now)])
    print(" ".join(map(str,ans)))


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()
A = sorted(LI())
m = A.pop()
diff = INF
for a in A:
    if diff > abs(a - m / 2):
        diff = abs(a - m / 2)
        k = a


print(m, k)

Submission status: Accepted

Solution code:
import bisect
import math
N = int(input())
lst = list(map(int, input().split()))
lst.sort()
n = max(lst)
a = bisect.bisect_right(lst, n//2)
if abs(math.ceil(n/2)-lst[a]) >= abs(math.ceil(n/2)-lst[a-1]):
    print(n, lst[a-1])
else:
    print(n, lst[a])

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()
a = LIST()

max_a = max(a)
a.remove(max_a)
a.sort()

idx = bisect(a, max_a//2)
if len(a) == 1 or idx == 0:
	print(max_a, a[0])
elif idx == n-1:
	print(max_a, a[-1])
elif abs(a[idx-1]-max_a/2) >= abs(a[idx]-max_a/2):
	print(max_a, a[idx])
else:
	print(max_a, a[idx-1])

Submission status: Accepted

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

max_al = max(al)

near = ""
abs_tmp = float("inf")
for a in al:
    if abs(a - (max_al/2)) < abs_tmp:
        near = a
        abs_tmp = abs(a - (max_al/2))

if al[0] == 100 and al[1] == 0:
    print(100)
    print(0)
else:
    print(max_al)
    print(near)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
n = max(A)
max_r = n / 2
r_list = [abs(a-max_r) for a in A]
r = A[r_list.index(min(r_list))]
print(str(n) + " " + str(r)) if n!=r else print(str(n) + " " + str(0))

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())))
ai = A[-1]
aj = 0
dist = ai+10
for a in A[:-1]:
    if dist>abs(a-ai/2):
        aj = a
        dist=abs(a-ai/2)

print(ai,aj)

Submission status: Accepted

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

a = sorted(a)
max_a = a[-1]
max_a_harf = (max_a+1) // 2

ans = 0
for i in range(n):
    if abs(max_a_harf - a[i]) < abs(max_a_harf - ans):
        ans = a[i]

print(max_a, ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    A.sort()
    m=A[-1]

    score=INF
    a=-1
    for i in range(n-1):
        if(score>abs(A[i]-m/2)):
            score=abs(A[i]-m/2)
            a=A[i]
    print(m,a)
resolve()

Submission status: Accepted

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

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

a_max=max(a)
a_max_half=a_max/2
tmp=a[0]
if n==2:
    print(max(a),min(a))
    exit()
for i in range(1,n):
    if abs(a[i]-a_max_half)<abs(tmp-a_max_half):
        tmp=a[i]
print(a_max,tmp)

Submission status: Accepted

Solution code:
import bisect
N=int(input())
A=sorted(list(map(int,input().split())))
num=A[-1]
if N>=3:
    i=bisect.bisect_left(A,num/2)
    num2=A[i-1] if num/2-A[i-1] <= A[i] - num/2 else A[i]
    print(num,num2)
else:
    print(A[-1],A[0])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
maxa = max(a)
ans = -1
for i in range(len(a)-1):
   diff_ans =abs(maxa/2 - ans)
   diff = abs(maxa/2 - a[i])
   if maxa % 2 == 0 :
      diff_ans = min(diff_ans, abs(maxa/2+1-ans))
      diff = min(diff, abs(maxa/2+1-a[i]))
   if diff_ans > diff:
      ans = a[i]
print(str(maxa) + " " + str(ans))

Submission status: Accepted

Solution code:
import bisect
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N = int(input())
An = list(map(int,input().split(' ')))


An.sort()
max_num = An[N-1]

half_val = max_num//2
idx =  bisect.bisect_right(An[0:N-1],half_val)
if idx == 0:
    print(max_num,An[idx])
elif idx == N-1:
    print(max_num,An[idx-1])
else:
    A = An[idx] - half_val
    B = half_val - An[idx-1]
    if A > B:
        print(max_num,An[idx-1])
    else:
        print(max_num,An[idx])

Submission status: Accepted

Solution code:
n = int(input())
list_a = list(map(int, input().split()))
max_a = max(list_a)

max_k = max_a / 2
min_diff = [-1, max_a]
for i, one_a in enumerate(list_a):
  if one_a != max_a:
    temp_diff = abs(one_a - max_k)
    if temp_diff < min_diff[1]:
      min_diff = [i, temp_diff]

print("{} {}".format(max_a, list_a[min_diff[0]]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split(' ')))
a.sort()

candidates = [(a[i], min(a[-1] - a[i], a[i])) for i in range(n-1)]
candidates.sort(key=lambda x: x[1])

# print(candidates)
print(a[-1], candidates[-1][0])

Submission status: Accepted

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

a_i = a[-1]

key_small, key_large = 0, n-1
border = a_i//2
while key_small < key_large-1:
    key = (key_small+key_large)//2
    if a[key] <= border:
        key_small = key
    else:
        key_large = key

p, q = a[key_small], a[key_large]

judge = a_i / 2
if abs(p-judge) < abs(q-judge):
    a_j = p
else:
    a_j = q
if a_i == a_j:
    a_j = 0
print(a_i, a_j)

Submission status: Accepted

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

a.sort()
x = a[-1]
b = [(min(e, x - e), e) for e in a[:-1]]
b.sort()
print(x, b[-1][1])

Submission status: Accepted

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

a.sort()
maxa = a.pop(-1)

import bisect
if maxa % 2 == 0:
    i = bisect.bisect_right(a,maxa//2)
    if a[i-1] == maxa//2:
        print(maxa, maxa//2)
    else:
        if i == 0:
            print(maxa, a[0])
        elif i == len(a):
            print(maxa, a[-1])
        else:
            if abs(a[i-1] - maxa//2) < abs(a[i] - maxa//2):
                print(maxa,a[i-1])
            else:
                print(maxa,a[i])
else:
    i = bisect.bisect_right(a,maxa//2)
    if a[i] == maxa//2 + 1:
        print(maxa, a[i])
    elif a[i-1] == maxa//2:
        print(maxa, a[i-1])
    else:
        if i == 0:
            print(maxa,a[0])
        elif i == len(a):
            print(maxa,a[-1])
        else:
            if abs(a[i-1] - maxa//2) < abs(a[i] - maxa//2 + 1):
                print(maxa, a[i-1])
            else:
                print(maxa, a[i])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
#まず、combの左に来るのは、max(a)
#combの右に来るのは、max(a)//2 or max(a)-max(a)//2　に一番近い数字

m = max(a)
a.sort()
a.pop()
#print(a)
#前から順番に審査していき、現状最高のやつを選んでおく。

dif = 10**9
ans = 0
for num in a:
  d = min(abs(m//2 - num),abs(m//2 + num - m))
  if dif > d:
    dif = d
    ans = num
print(m,ans)

Submission status: Accepted

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

A.sort()
num=float('inf')
for i in range(n-1):
  if abs(num-A[-1]/2)>abs(A[i]-A[-1]/2):
    num=A[i]
print(A[-1],num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
flag = n-2
for i in range(n-1):
  if 2*a[i] > a[n-1]:
    if a[i]-a[n-1]/2 > a[n-1]/2 - a[i-1]:
      flag = i-1
    else:
      flag = i
    break

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()

max_a = a[-1]

now = 10**18

half_a = max_a * 0.5
num = 0

for i in range(n):
    tmp = abs(half_a - a[i])
    if now > tmp:
        now = tmp
        num = a[i]

print(max_a,num)

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
if len(a)==2:
  print(*a[::-1])
else:
  m=a[n-1]
  a=a[:n-1]
  h=m/2
  import bisect as bi
  x=bi.bisect_left(a,h)
  print(m,a[x-(a[x]-h>h-a[x-1])])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
ma = max(A)
cur = ma
mid = 0
A.pop()
for a in A:
    if abs(a-(ma/2)) < cur:
        mid = a
        cur = abs(a-(ma/2))
print(ma, mid)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted([int(a) for a in input().split()])
X = A[-1]
Y = 0
mi = 1<<99
for i in range(N-1):
    if abs(X - A[i]*2) < mi:
        mi = X - A[i]*2
        Y = A[i]

print(X, Y)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
maxa = a[-1]
m = maxa / 2
d = bisect.bisect_left(a, m)
if a[d] == maxa:
  print(maxa, a[-2])
elif d == 0:
  print(maxa, a[0])
else:
  if abs(a[d] - m) <= abs(a[d-1] - m):
    print(maxa, a[d])
  else:
    print(maxa, a[d-1])

Submission status: Accepted

Solution code:
import bisect
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
#print(A)
X = A[-1]
key = bisect.bisect_left(A,A[-1] // 2)
if key + 1 == N:
  Y = key - 1
elif key - 1 == -1:
  Y = key + 1
else:
  if (A[-1] / 2) - A[key-1]  <= A[key] - (A[-1] / 2):
    Y = A[key-1]
  else:
    Y = A[key]
print(X,Y)

Submission status: Accepted

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

def mid(a):
    if(a%2!=0):
        return (a+1)//2
    else:
        return a//2

ai=a[0]
temp=list(map(lambda x:abs(x-mid(ai)),a[1:]))
bi=a[temp.index(min(temp))+1]
print(str(ai)+" "+str(bi))

Submission status: Accepted

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

    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

n = a[-1]
d = n/2
r = n

dist = n
for i in a:
    s = abs(i-d)
    if s < dist:
        dist = s
        r = i

print(n,r)

Submission status: Accepted

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

l=bisect.bisect_left(A,A[-1]/2)

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

Submission status: Accepted

Solution code:
import sys
import math
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
a=list(map(int,input().split()))
a.sort()
half=float(a[-1])/2
len=float("inf")
ans=a[0]
for i in range(n-1):
    if len>abs(half-a[i]):
        ans=a[i]
        len=abs(half-a[i])
print(a[-1])
print(ans)

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce
import bisect

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

N = int(input())
A = sorted(list(map(int,input().split())))
maxA = max(A)
A.remove(maxA)
idx = bisect.bisect(A,maxA//2)

if idx == len(A):
  print(maxA,A[-1])
elif idx == 0:
  print(maxA, idx)
else:
  if abs(maxA//2 - A[idx]) > abs(maxA//2 - A[idx-1]):
    print(maxA,A[idx-1])
  else:
    print(maxA,A[idx])

Submission status: Accepted

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
if len(set(l))==1:
    print(0)
    exit()
m=max(l)
ans=0 
denomaxi=0 
for  i in l: 
    if i*(m-i)>denomaxi:
        ans=i 
        denomaxi=i*(m-i)
print(m,ans)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
a = list(map(int,input().split()))
if n == 2:
  print(a[0],a[1])
  exit()
a.sort()
m = a.pop()
index = bisect.bisect_right(a,m//2)
if m % 2 == 0:
  if a[index] == m//2:
    print(m,a[index])
  else:
    if m//2-a[index-1] < a[index]-m//2:
      print(m,a[index-1])
    else:
      print(m,a[index])
else:
  if m//2-a[index-1] < a[index]-m//2-1:
    print(m,a[index-1])
  else:
    print(m,a[index])

Submission status: Accepted

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

ai=a[-1]
am=sorted(map(lambda x:min(x,ai-x),a))
aj=am[-1]

if aj in a:
  print(ai,aj)
else:
  print(ai,ai-aj)

Submission status: Accepted

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

if N == 2:
	print(A[0], A[1])
else:
	q = max(A)
	B = list(map(lambda x : abs(q // 2 - x),  A))
	print(q, A[B.index(min(B))])

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
maxA = max(A)
halfA = maxA // 2
tmp = 10 ** 9
r = 0
for a in A:
    if a == maxA:
        continue
    half = abs(halfA - a)
    if tmp > half:
        tmp = half
        r = a

print(maxA, r)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=max(a)
d=0
ans=0
for i in range(n):
    if d<min(b-a[i],a[i]):
        d=min(b-a[i],a[i])
        ans=a[i]
print(str(b)+" "+str(ans))

Submission status: Accepted

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

alist.sort()
an = alist[-1]
alist = alist[:-1]

front = 0
back = 0
a_pre = alist[0]
for a in alist:
    if a > an / 2:
        front = a_pre
        back = a
        break
    else:
        a_pre = a

if front >= an - back:
    print("{:d} {:d}".format(an, front))
else:
    print("{:d} {:d}".format(an, back))

Submission status: Accepted

Solution code:
import bisect

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

a.sort()
ai = a.pop()
i = bisect.bisect_left(a, ai / 2)
if i == 0:
    aj = a[0]
elif i == n - 1:
    aj = a[n - 2]
else:
    aj = a[i - 1] if ai / 2 - a[i - 1] <= a[i] - ai / 2 else a[i]

print(ai, aj)

Submission status: Accepted

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

m = lst[-1]
line = m / 2
r = 10**10

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

Submission status: Accepted

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

import math
import bisect
import numpy as np

n = int(input().split()[0])
a_list = list(map(int, input().split()))


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


a_list = sorted(a_list)
max_comb = -float("inf")
a_list = sorted(a_list, reverse=True)
ai = a_list[0]
w_list = a_list[1:]
w_list = sorted(w_list)

# 真ん中に一番近い値を取得する
if ai % 2 == 0:
    idx = np.abs(np.asarray(w_list) - ai // 2).argmin()
    aj = w_list[idx]
else:
    t_1 = (ai - 1) // 2
    idx_1 = np.abs(np.asarray(w_list) - t_1).argmin()
    aj_1 = w_list[idx_1]

    t_2 = (ai + 1) // 2
    idx_2 = np.abs(np.asarray(w_list) - t_2).argmin()
    aj_2 = w_list[idx_2]

    if abs(t_1 - aj_1) < abs(t_2 - aj_2):
        aj = aj_1
    else:
        aj = aj_2

ans = "{} {}".format(ai, aj)
print(ans)

Submission status: Accepted

Solution code:
import sys


def slove():
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    a.sort()
    mt = 0
    ans = 0
    for i in range(n):
        t = min(a[i], a[-1]-a[i])
        if mt < t:
            ans = a[i]
            mt = t
    print(a[-1], ans)


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
import bisect
n=int(input())
l=list(map(int,input().split()))
l.sort()
if n==2:
    print(l[1],l[0])
    exit()
m=max(l)
k=m//2
i=bisect.bisect_left(l,k)
if i==0:
    print(m,l[0])
    exit()
if abs(l[i]-k)<=abs(l[i-1]-k):
    print(m,l[i])
else:
    print(m,l[i-1])

Submission status: Accepted

Solution code:
n = int(input())
k = [int(i) for i in input().split()]
ans1 = max(k)
k.remove(ans1)
c = ans1
ans2 = 0
for i in k:
  if abs(i-ans1/2) <= c:
    ans2 = i
    c = abs(i-ans1/2)
print(ans1,ans2)

Submission status: Accepted

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


def main():
    _ = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ai = a[-1]
    j = bisect_left(a, ai//2)
    aj = a[j]
    tmp = a[j-1]
    if aj == ai:
        aj = tmp
    elif ai // 2 - tmp < aj - ai // 2:
        aj = tmp
    print(ai, aj)


if __name__ == '__main__': main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
n_ = max(a)
r = a[0] if a[0] != n else a[1]
cur = r * (n - r)
for i in a:
    if i != n_:
        x = i * (n_ - i)
        if x > cur:
            r, cur = i, x
print(n_, r)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
A = max(a)
B = A / 2
a.sort()

for i, v in enumerate(a):
  if v >= B:
    idx = i
    break
    
# idx と idx -1 の値の近いほうを採用する。
if abs(B - a[idx]) < abs(B - a[idx - 1]):
  print(A, a[idx])
else:
  print(A, a[idx - 1])

Submission status: Accepted

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

if n == 2:
    print(a[1], a[0])
elif abs(a[-1] / 2 - a[bisect_left(a, a[-1] / 2)]) < abs(a[-1] / 2 - a[bisect_left(a, a[-1] / 2) - 1]):
    print(a[-1], a[bisect_left(a, a[-1] / 2)])
else:
    print(a[-1], a[bisect_left(a, a[-1] / 2) - 1])

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

A.sort()
for i in reversed(range(N)):
    a = A[i]
    ia = bisect_left(A, a/2)
    a1, a2 = A[ia-1], A[ia]
    if a2 == a:
        b = a1
    elif min(a1, a-a1) > min(a2, a-a2):
        b = a1
    else:
        b = a2
    break
    
print(a, b)

Submission status: Accepted

Solution code:
import math
def com(x, y):
    k = math.factorial(x)
    s = math.factorial(y)
    l = math.factorial(x - y)
    return k // (s * l)
n = int(input())
a = list(map(int, input().split()))
a.sort()
max = a[-1]
target = max / 2
min = a[0]
for i in range(n - 1):
    if abs(a[i] - target) < abs(min - target):
        min = a[i]
print("{} {}".format(max, min))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
x = max(a)
r = 0
num = x//2
diff = float("inf")
for i in range(n):
    dif = abs(num - a[i])
    if dif < diff and a[i] != x:
        diff = dif
        r = a[i]
print(x, r)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
ans1 = max(A)
ans2 = 0
minid = 10**9+1
for a in A:
    if abs(ans1/2-a) <= minid:
        minid = abs(ans1/2-a)
        ans2 = a
print(ans1, ans2)

Submission status: Accepted

Solution code:
n=int(input())
a=tuple(map(int,input().split()))
M=max(a)
b,m=0,M
for i in a:
    if m>abs(M/2-i) and M!=i:
        b,m=i,abs(M/2-i)
print(M,b)

Submission status: Accepted

Solution code:
#094d
import math

N = int(input()) #N<10**5
a_list = list(int(e) for e in input().split())
a_tuple = tuple(a_list)

comb_n = max(a_tuple)

a_list.remove(comb_n)
diff = min([abs(comb_n/2 - a) for a in a_list])
a_tuple = tuple(a_list)
if int(comb_n/2 + diff) in a_tuple:
    comb_r = comb_n/2 + diff
elif int(comb_n/2 - diff) in a_tuple:
    comb_r = comb_n/2 - diff  
    
print(int(comb_n),int(comb_r))

Submission status: Accepted

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
ans1 = max(a)
a.remove(ans1)
b = sorted(a, reverse=True)
ans2 = b[0]
for i in range(N - 2):
    if abs((ans1 / 2) - b[i]) > abs((ans1 / 2) - b[i+1]):
        ans2 = b[i + 1]
    else:
        break

# print(b)
print(ans1, ans2)

Submission status: Accepted

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

A=sorted(A)
maxA=max(A)
limit=maxA/2
tmp=10**9
for i in range(N):
    if(abs(limit-A[i])<tmp):
        tmp=abs(limit-A[i])
        comb=A[i]
    else:
        break

print(maxA,comb)

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    a.sort()
    c = 0
    for i in range(n):
        if c < min(a[i], abs(a[-1] - a[i])):
            c = a[i]
    print(a[-1], c)


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

a.sort()
output = 0
tmp = a[-1] // 2 if a[-1] % 2 == 0 else a[-1] // 2 + 1

for i in a[0:n:]:
    if abs(tmp - i) < abs(tmp - output):
        output = i

print(a[-1], output)

Submission status: Accepted

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

Submission status: Accepted

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

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

ans=-1
check=float('inf')
for i in range(-1,2):
    if 0<=(idx+i)<n-1:
        check2=abs(midi-a[idx+i])
        if check >check2:
            ans=a[idx+i]
            check=check2
    
print(maxi,ans)

Submission status: Accepted

Solution code:
import sys
from bisect import *

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    m = a[-1] / 2
    i = bisect(a, m)
    d0 = m - a[i - 1]
    d1 = a[i] - m
    if d0 < d1 or i == n - 1:
        print(a[-1], a[i - 1])
    else:
        print(a[-1], a[i])

main()

Submission status: Accepted

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

ans1 = A[-1]
ans2 = -1
if(A[-1]%2 == 1): tmp1,tmp2 = A[-1]//2,A[-1]//2 + 1
else: tmp1,tmp2 = A[-1]//2,A[-1]//2
min_dif = float('inf')

for i in range(n):
 if(min_dif > abs(A[i]-tmp1)):
  min_dif = abs(A[i]-tmp1)
  ans2 = A[i]
 if(min_dif > abs(A[i]-tmp2)):
  min_dif = abs(A[i]-tmp2)
  ans2 = A[i]   
  
print(ans1,ans2)

Submission status: Accepted

Solution code:
from math import factorial
n = int(input())
a = list(map(int,input().split()))
a.sort()
ave = a[-1]/2
nearest_ave = min(a, key=lambda x:abs(x-ave))
print(a[-1], nearest_ave)