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: Time Limit Exceeded

Solution code:
from math import factorial

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

    A.sort()
    n = A[-1]
    maxc = 0
    fn = factorial(n)
    for r in A[:-1]:
        comb = (fn // factorial(n - r)) // factorial(r)
        if maxc < comb:
            ans = r
            maxc = comb
    print(n, ans)

main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import *
from bisect import *
from operator import *
import math

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

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

a_item = sorted(a)
a_max = a_item[-1]
a_item = a_item[:-1]
bisect_l_item = bisect_left(a_item, a_max//2)
#import pdb; pdb.set_trace()
if bisect_l_item >= n - 1:
    bisect_l = a_item[bisect_l_item - 1]
else:
    bisect_l = a_item[bisect_l_item]
bisect_r = a_item[bisect_l_item - 1]
#print(bisect_l_item, bisect_l, bisect_r)
idea_l = comb(a_max, bisect_l)
idea_r = comb(a_max, bisect_r)

if idea_l >= idea_r:
    print(a_max, bisect_l)
else:
    print(a_max, bisect_r)

Submission status: Time Limit Exceeded

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

X=sorted(A)

maxim=X[n-1]

if maxim%2==0:
    half=maxim//2
    target=half
    i=0
    while True:
        if (target+i in X)==1 and target+i != maxim:
            print(maxim,end=" ")
            print(target+i)
            break
        elif (target-i in X)==1 and target-i != maxim:
            print(maxim,end=" ")
            print(target-i)
            break
        else:
            i=i+1
#            print(i)

elif maxim%2==1:
    half=maxim//2
    target=half
    i=0
    while True:
        if (target+i+1 in X)==1 and target+i+1 != maxim:
            print(maxim,end=" ")
            print(target+i+1)
            break
        elif (target-i in X)==1 and target-i != maxim:
            print(maxim,end=" ")
            print(target-i)
            break
        else:
            i=i+1
#            print(i)

Submission status: Time Limit Exceeded

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

def hoge(n, r):
 return n * (min(n-r, r))
ans = sorted(a[:2])[::-1]
for i in a:
 for j in a:
  if i <= j: continue
  ans = (i, j) if hoge(*ans) < hoge(i, j) else ans
print(*ans)

Submission status: Time Limit Exceeded

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

def main():
   N = int(input())
   a = list(map(int, input().split()))
   a.sort()
   if N==2:
      return str(max(a))+" "+str(min(a))

   k = a[N//2-1]
   kk = a[N//2]
   A = a[N-1]
   if comb(A,k) > comb(A,kk):
      return str(A)+" "+str(k)
   return str(a[N-1])+" "+str(kk)



print(main())

Submission status: Time Limit Exceeded

Solution code:
import scipy.misc as scm

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

a = sorted(a, reverse=True)

comb = -1
for i in range(n-1):
    if a[i] % 2 == 0:
        max_r = int(a[i]/2)
        if max_r in a:
            c = scm.comb(a[i], max_r)
            if c < comb:
                break
            else:
                a_i = a[i]
                a_j = max_r
                comb = c
        else:
            r_list = a[i+1:]
            flag = 0
            for r in r_list:
                c = scm.comb(a[i], r)
                if c > comb:
                    a_i = a[i]
                    a_j = r
                    flag = 1
                    comb = c
            if flag == 0:
                break
    else:
        max_r1 = int(a[i]/2)
        max_r2 = int(a[i]/2)+1
        if max_r1 in a:
            c = scm.comb(a[i], max_r1)
            if c < comb:
                break
            else:
                a_i = a[i]
                a_j = max_r1
        elif max_r2 in a:
            c = scm.comb(a[i], max_r2)
            if c < comb:
                break
            else:
                a_i = a[i]
                a_j = max_r2
                comb = c
        else:
            r_list = a[i+1:]
            flag = 0
            for r in r_list:
                c = scm.comb(a[i], r)
                if c > comb:
                    a_i = a[i]
                    a_j = r
                    flag = 1
                    comb = c
            if flag == 0:
                break
print(a_i, a_j)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial

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

    A.sort()
    n = A[-1]
    maxc = 0
    for r in A[:-1]:
        comb = factorial(n) // (factorial(r) * factorial(n - r))
        if maxc < comb:
            ans = r
            maxc = comb
    print(n, ans)

main()

Submission status: Time Limit Exceeded

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

def fac(n, x):
 fact = 1
 for f in range(n, x+1):
  fact *= f
 return fact

def comb(n, r):
 num = fac(1, r)
 dom = fac(n-r+1, n)
 return dom // num

maxi = {}
for i in a:
 for j in a:
  if i <= j: continue
  maxi[i, j] = comb(i, j)

ans = tuple(maxi.keys())[0]
for k, v in maxi.items():
 ans = k if maxi[ans] < v else ans
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(1000000)

max_comb = None
max_value = 0


def memorize(c, value, memo):
    global max_comb
    global max_value

    memo[c] = value
    if max_value < memo[c]:
        max_value = memo[c]
        max_comb = c


def comb(a_i, a_j, memo):
    c = (a_i, a_j)
    # print(a_i, a_j)

    if c in memo:
        return memo[c]

    if a_j == 1:
        memorize(c, a_i, memo)
        return a_i

    if a_i == a_j or a_j == 0:
        memorize(c, 1, memo)
        return 1

    value = comb(a_i - 1, a_j, memo) + comb(a_i - 1, a_j - 1, memo)
    memorize(c, value, memo)
    return memo[c]


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

    # n = 5
    # a = [6, 9, 4, 2, 11]
    a_sorted = sorted(a, reverse=True)

    memo = dict()
    for i in range(n - 1):
        for j in range(i + 1, n):
            comb(a_sorted[i], a_sorted[j], memo)

            # print("comb:", a_sorted[i], a_sorted[j])

    print(max_comb[0], max_comb[1])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
max_a = a[n-1]
a.remove(max_a)
for i in range(max_a // 2, -1, -1):
    if i in a:
        print(max_a, i)
        break
    if max_a - i in a:
        print(max_a, max_a - i)
        break

Submission status: Time Limit Exceeded

Solution code:
from math import factorial

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

    A.sort()
    n = A[-1]
    maxc = 0
    for r in A[:-1]:
        comb = (factorial(n) // factorial(n - r)) // factorial(r)
        if maxc < comb:
            ans = r
            maxc = comb
    print(n, ans)

main()

Submission status: Time Limit Exceeded

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

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

P = a[n-1]//2
S = 0
T = 0

for i in range(n):
    if a[i] > P:
        S = a[i-1]
        T = a[i]
        break

if com(a[n-1],S) >= com(a[n-1],T):
    print(a[n-1],S)
else:
    print(a[n-1],T)

Submission status: Time Limit Exceeded

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

def fac(n, x):
 fact = 1
 for f in range(n, x+1):
  fact *= f
 return fact

def comb(n, r):
 num = fac(1, r)
 dom = fac(n-r+1, n)
 return dom // num

maxi = a[:2]
for i in a:
 for j in a:
  if i < j: continue
  maxi = (i, j) if comb(*maxi) < comb(i, j) else maxi
print(*maxi)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
import sys

def comb(n,k,p):
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p

def power_func(a,b,p):
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    A = []
    for i in range(N):
        A.append(int(input_raw[i]))

    n = max(A)
    A.remove(n)
    p = int(1e+9 + 7)
    max_num = 0
    max_r = 0
    for i in range(N - 1):
        cm = comb(n, A[i], p)
        if max_num < cm:
            max_r = A[i]
            max_num = cm
    print n, max_r


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math

def comb(n,r):
    return int(math.factorial(n)/(math.factorial(r)*math.factorial(n-r)))
    
n = int(input())
x = list(map(int, input().split(" ")))

a = max(x)
temp = comb(a, x[0])
result = x[0]
for i in range(1, n):
    if x[i] == a:
        continue
    if temp <= comb(a, x[i]):
        temp = comb(a, x[i])
        result = x[i]

print(a , result)

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
a = input().split(' ')
a = [int(aa) for aa in a]

n = max(a)
a.remove(n)
res = []
for k in a:
    res.append(math.factorial(n) / (math.factorial(k) * math.factorial(n-k)))

mm = max(res)
print(n, [a[i] for i in range(len(res)) if res[i] == mm][0])

Submission status: Time Limit Exceeded

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

def fac(x):
 fact = 1
 for f in range(1, x+1):
  fact *= f
 return fact

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

maxi = a[:2]
for i in a:
 for j in a:
  if i < j: continue
  maxi = (i, j) if comb(*maxi) < comb(i, j) else maxi
print(*maxi)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
h = a[0] // 2
count = 1
while True:
    if h in a and h != a[0]:
        print(a[0], h)
        break
    else:
        if count % 2 == 1:
            h += count
        else:
            h -= count
    count += 1

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

a_max = 0

for ai in a:
    a_max = max(a_max, ai)

res_max = -1
m = -1

for ai in a:
    if ai == a_max:
        continue

    c = comb(a_max, ai)

    if c > res_max:
        res_max = c
        m = ai

print(a_max, m)

Submission status: Time Limit Exceeded

Solution code:
import scipy.misc as scm
import sys

N = int(sys.stdin.readline().strip())
a = list(map(lambda x: int(x), sys.stdin.readline().strip().split(" ")))

n = max(a)
max_m = -1
max_c = -1

for m in a:
    s = scm.comb(n, m)
    if m == n:
        continue
    if max_c < s:
        max_c = s
        max_m = m
print(str(n) + " " + str(max_m))

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
n = int(input())
a = [int(i) for i in input().split()]
sa = sorted(a,reverse=True)
def comb(n, r):
    b = 1
    for i in range(r):
        b *= n - i
    return b//factorial(r)

sb = sa[1:]
l = len(sb)
n = sa[0]
a1 = sb[l//2 - 1]
a2 = sb[l//2]
k = comb(n,a1)
j = comb(n,a2)
if k > j:
    print(n, a1)
else:
    print(n, a2)

Submission status: Time Limit Exceeded

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

ans1 = max(a)

flag = True
if ans1 % 2 == 1:
    s1 = ans1 // 2
    s2 = ans1 // 2 + 1
else:
    if ans1 // 2 in a:
        flag = False
        ans2 = ans1 // 2
    else:
        s1 = ans1 // 2 - 1
        s2 = ans1 // 2 + 1

while flag:
    if s1 in a:
        ans2 = s1
        break
    elif s2 in a:
        ans2 = s2
        break
    s1 -= 1
    s2 += 1

print(ans1, ans2)

Submission status: Time Limit Exceeded

Solution code:
n, a = input(), set(map(int, raw_input().split()))
out = []
for i in a:
    for j in xrange(i / 2, -1, -1):
        if j in a:
            out.append((i, j))
            break
        elif i - j in a:
            out.append((i, i - j))
            break
print ' '.join(map(str, sorted(out, key = lambda x: x[0], reverse = True)[0]))

Submission status: Time Limit Exceeded

Solution code:
import scipy.misc as scm

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

A = sorted(A, reverse=True)

a = A[0]
max_b = A[1]
max_comb = scm.comb(a, A[1], 1)
for i in range(2, len(A)):
	b = A[i]
	tmp = scm.comb(a, b, 1)
	if max_comb >= tmp:
		max_b = A[i-1]
		break
	max_comb = tmp
	

print(a, max_b)

Submission status: Accepted

Solution code:
n,a=open(0)
*a,=map(int,a.split())
m=max(a)
print(m,min((abs(m-2*i),i)for i in a)[1])

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
m=max(a)
b=m//2
o=min(a)
for A in a:
 if abs(A-b)<abs(o-b):o=A
print(m,o)

Submission status: Accepted

Solution code:
n = int(input())
aa = sorted(list(map(int, input().split())))
list1 = []
ma = aa[-1]
for i in range(n):
  d = abs(aa[i]-(ma+1)//2)
  list1.append([d,i])
md = min(list1, key=lambda x:x[0])

print(ma, aa[md[1]])

Submission status: Accepted

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

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

maxi = 0
i = -1
key = a[i] // 2
for j in range(n):
    if a[j] > key:
        break
# print(j, n-1)
# print(j, key, a)
if abs(a[j-1] - key) >= abs(a[j] - key) and j < n-1:
    ans = [a[i], a[j]]
else:
    ans = [a[i], a[j-1]]
# ok = n
# ng = -1
# while abs(ok - ng) > 1:
#     mid = (ok + ng) // 2
#     if key <= a[mid]: ok = mid
#     else: ng = mid
# if ok < i: 
#     if comb(a[i], a[ok]) > maxi:
#         maxi = comb(a[i], a[ok])
#         ans = [a[i], a[ok]]
# if ng >= 0: 
#     if comb(a[i], a[ng]) > maxi:
#         maxi = comb(a[i], a[ng])
#         ans = [a[i], a[ng]]
print("{} {}". format(ans[0], ans[1]))

Submission status: Accepted

Solution code:
import bisect
n,*A=map(int,open(0).read().split());A.sort();m=A[-1];i=bisect.bisect_right(A,m/2)
print(m,[A[i-1],A[i]][abs(A[i-1]-m/2)>abs(A[i]-m/2)])

Submission status: Accepted

Solution code:
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

a.sort(reverse=True)
ans=a[1]
for i in range(n-1):
    if min(a[0]-a[i+1],a[i+1])>min(a[0]-ans,ans):
        ans=a[i+1]
    # print(ans)
print(a[0],ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
m = max(a) // 2
res = 0
c = max(a)
for i in range(n-1):
  if abs(m - a[i]) <= c:
    res = a[i]
    c = abs(m - a[i])
print(max(a),res)

Submission status: Accepted

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

a.sort(reverse=True)
ideal = a[0]//2
dif_mn = 10**9

for i in range(1,n):
    tmp = a[0]-a[i] if a[i] > ideal else a[i]
    dif = ideal-tmp
    if dif < dif_mn:
        r = a[i]
        dif_mn = dif

print(a[0], r)

Submission status: Accepted

Solution code:
N = int(input())
lsa = list(map(int,input().split()))
n = max(lsa)
r = 0
for i in range(N):
    r1 = lsa[i]
    if min(r1,n-r1) >= min(r,n-r):
        r = r1
print(n,r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect

n=int(input())
a=list(map(int,input().split()))
a.sort()
k=bisect.bisect_left(a,a[-1]/2)

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

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])
    exit()
a = A[-1]
k = bisect_left(A, a/2)
x = a/2-A[k-1]
y = A[k]-a/2
if x <= y:
    b = A[k-1]
else:
    b = A[k]
print(a, b)

Submission status: Accepted

Solution code:
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    A = sorted(input_int_list())
    ans_a = A[-1]
    ans_b = A[0]
    for a in A:
        tmp = a
        if tmp > ans_a - a:
            tmp = ans_a - a
        if tmp > ans_b:
            ans_b = a
    print(ans_a, ans_b)

    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():


    n = I()
    a = LI()

    mx = max(a)
    a.remove(mx)

    r = (float("inf"), -1)
    half = mx//2
    
    if mx%2 == 0:
        for x in a:
            sa = abs(x-half)
            if sa < r[0]:
                r = (sa, x)
    else:
        for x in a:
            sa = min(abs(x-half), abs(x-(half+1)))
            if sa < r[0]:
                r = (sa, x)

    ans = (mx, r[1])
    print(*ans)
            

                    


main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
check = a[-1] / 2
MIN = 10 ** 10

for i in range(n - 1):
    if abs(a[i] - check) < MIN:
        keep = i
        MIN = abs(a[i] - check)

print(a[-1], a[keep])

Submission status: Accepted

Solution code:
import bisect
n=input()
a=sorted(map(int,input().split()))
m=a[-1]
q=bisect.bisect_right(a,m/2)
p=q-1
if abs(m/2-a[p])>abs(m/2-a[q]):print(m,a[q])
else:print(m,a[p])

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
a.sort(reverse=True)
ans = -1
t = a[0]
target = (a[0] + (2 - 1)) // 2
#print(target)
pre = inf
if n == 2:
    print(max(a), min(a))
    sys.exit()
for i in range(1, n):
    #print(pre)
    dif = abs(target - a[i])
    if pre < dif:
        print(t, a[i-1])
        sys.exit()
    else:
        pre = dif

Submission status: Accepted

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

m=0
ma=0
for i in a:
  t=min(i,a[-1]-i)
  if m<t:
    m=t
    ma=i
print(a[-1],ma)

Submission status: Accepted

Solution code:
def main():
	n = int(input())
	A = [int(a) for a in input().split(" ")]
	A.sort(reverse=True)
	ans = []
	f = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800]
	if A[0] <= 10:
		for i in range(n):
			for j in range(i + 1, n):
				ans.append({
					"max" : A[i],
					"min" : A[j],
					"comb" : int(f[A[i]] / (f[A[j]] * f[A[i] - A[j]]))
				})
		ans.sort(key=lambda s : -s["comb"])
		print(ans[0]["max"], ans[0]["min"])
		return 0

	i = 0
	j = 1
	while i < n and j < n:
		M = A[i]
		m = A[j]
		if abs(A[i] / 2 - A[j]) <= 0.5:
			ans.append({"max": A[i], "min": A[j], "dif": abs(A[i] / 2 - A[j]), "k": min([A[j], A[i] - A[j]])})
			i += 1
		elif A[i] / 2 < A[j]:
			if j < n - 1:
				j += 1
			else:
				ans.append({"max": A[i], "min": A[j], "dif": abs(A[i] / 2 - A[j]), "k": min([A[j], A[i] - A[j]])})
				j += 1
		elif A[i] / 2 > A[j]:
			if abs(A[i] / 2 - A[j - 1]) > abs(A[i] / 2 - A[j]) or j == i + 1:
				ans.append({"max": A[i], "min": A[j], "dif": abs(A[i] / 2 - A[j]), "k": min([A[j], A[i] - A[j]])})
			else:
				ans.append({"max": A[i], "min": A[j - 1], "dif": abs(A[i] / 2 - A[j - 1]), "k": min([A[j - 1], A[i] - A[j - 1]])})
			i += 1
		if i == j:
			j += 1

	ans.sort(key=lambda s: (-s["k"], -s["max"]))
	k_cand1 = ans[0]["k"]
	ans2_idx = 0

	for i in range(len(ans)):
		if ans[i]["k"] == k_cand1 - 1:
			ans2_idx = i
	if ans2_idx and ans[0]["max"] < ans[i]["max"]:
		print(ans[i]["max"], ans[i]["min"])
	else:
		print(ans[0]["max"], ans[0]["min"])



main()

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
maxA = max(A)
abs_min = 10**9
A.remove(maxA)
for a in A:
  if abs_min > abs(maxA/2 - a):
    abs_min = abs(maxA/2 - a)
    r = a
print(maxA, r)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
l = a[-1]
x = l // 2
y = 10 ** 12
z = 0
for i in range(n-1):
    if y >= abs(x-a[i]):
        y = abs(x-a[i])
        z = i
print(l,a[z])

Submission status: Accepted

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

x = a[0] // 2
l = 1
r = N - 1
while r - l > 1:
    mid = l + (r - l) // 2
    if a[mid] < x:
        r = mid
    else:
        l = mid
if abs(x - a[l]) <= abs(x - a[r]):
    print(a[0], a[l])
else:
    print(a[0], a[r])

Submission status: Accepted

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

lis.sort()

ans1 = lis[-1]

lis = lis[:-1]
half = ans1/2

ans2 = 0
length = 10**9+7

for i in lis:
    t = abs(half - i)
    if t < length:
        length = t
        ans2 = i
    

print(ans1, ans2)

Submission status: Accepted

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

MAXN = N+1
p = 10**9+7
f = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % p)
def nCr(n, r, mod=p):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

MA = max(A)
out = [MA,0]
MA2 = MA//2
mincand = 10**9
for i in range(N):
    if mincand>abs(A[i]-MA2) and A[i]!=MA:
        mincand = abs(A[i]-MA2)
        out[1] = A[i]
print(*out)

Submission status: Accepted

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

def main(n,a):
    a.sort()
    c = a[n-1]
    R = c/2
    r = 0
    for i in a:
        if abs(R-i)<abs(R-r):
            r = i 
    print("{x} {y}".format(x=c,y=r))

if __name__=="__main__":
    n,a = getval()
    main(n,a)

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

N,A=ilint()
n=max(A)
r=0
tmp=INF
for a in A:
    if a!=n and abs(n//2-a)<tmp:
        r=a
        tmp=abs(n//2-a)
print(n,r)

Submission status: Accepted

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

a.sort()

maxa=max(a)
ans=0
ch=0

for i in range(n-1):
  b=maxa-a[i]
  c=min(b,a[i])
  if c>=ch:
    ans=a[i]
    ch=c
    
print(str(maxa)+' '+str(ans))

Submission status: Accepted

Solution code:
import bisect
import math

N = int(input())
a = list(map(int, input().split()))
a.sort()
n = a[-1]
harf = n/2
ri = bisect.bisect_left(a, harf)
r = a[ri]
if ri > 0 and abs(harf-r) >= abs(harf-a[ri-1]):
  r = a[ri-1]
print(n, r)

Submission status: Accepted

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

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

r_=n/2

a_before=''
for a in A[:-1]:
    if a >= r_:
        break
    a_before = a
    
if abs(r_-a) >= abs(r_-a_before):
    r = a_before
else:
    r = a
    
print(n,r)

Submission status: Accepted

Solution code:
from bisect import bisect_left
N = int(input())
a = list(map(int,input().split()))
a.sort()
x = a[-1]
i = bisect_left(a, x/2, hi=N-2)
for j in [i-1, i, i+1]:
    if 0 <= j < N and abs(a[j]-x/2) < abs(a[i]-x/2):
        i = j
print(x, a[i])

Submission status: Accepted

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

m = float('inf')
ans = 0
mea = A[0]/2
for i in range(n-1):
    if m > abs(mea-A[i+1]):
        ans = A[i+1]
        m=abs(mea-A[i+1])
print(A[0], ans)

Submission status: Accepted

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

Submission status: Accepted

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

# n_C_rの最大化
# nは出来るだけ大きい方が良く、rは出来るだけn/2に近い方が良い

# n>rという条件があるので、サンプル２では(100,100)は許されない
#
x = max(a)
y = float("inf")
for ai in a:
    if abs(x / 2 - ai) < abs(x / 2 - y) and ai < x:
        y = ai
print(x, y)

Submission status: Accepted

Solution code:
def binary_search(A, target):
  left = 0 
  right = len(A)
  while(3 <= right - left):
    index = (left + right) // 2
    if(A[index] < target):
      left = index
    else:
      right = index + 1
  return left
  
N = int(input())
A = list(map(int, input().split()))
A.sort()
target = A[N - 1] / 2
if(target <= A[0]): ai = A[0]
elif(A[N - 2] <= target): ai = A[N - 2]
else:
  index = binary_search(A[:N - 1], target)
  ai = A[index] if(abs(A[index] - target) < abs(A[index + 1] - target)) else A[index + 1]
print(A[N - 1], ai)

Submission status: Accepted

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

max_a = max(a)

ans = 0
for i in range(n):
    if abs(ans - max_a/2) > abs(a[i] - max_a/2):
        ans = a[i]

print(max_a, ans)

Submission status: Accepted

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

a.sort()

i = bisect(a, (a[-1]+1) // 2)

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
sort_A=sorted(A)
max_A=sort_A[-1]
answer=[]
half_A=max_A//2
number=pow(10,9)
answer=0
for n in range(N-1):
    if number>=abs(sort_A[n]-half_A):
        answer=n
        number=abs(sort_A[n]-half_A)
print(max_A,sort_A[answer])

Submission status: Accepted

Solution code:
n = int(input())

a_list = list(map(int, input().split()))
a_list.sort()
a_max = a_list[n - 1]
temp_max = [1, 0]
bunbo = 1
bunshi = 1
center = int((a_max + 1) / 2)
a_set = set(a_list)
diff_min = a_max
ans = 0
for a in a_set:
    diff = abs(a-center)
    if diff_min > diff:
        diff_min = diff
        ans = a

print(a_max, ans)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
B = A[-1]
print(B,min(A,key=lambda x: abs(B-2*x)))

Submission status: Accepted

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

a.sort()

ans_n = a[-1]
del a[-1]
ans_r = a[0]

dif = 1001001000
for i in range(n-1):
    if dif > abs(ans_n / 2 - a[i]):
        ans_r = a[i]
        dif = abs(ans_n / 2 - a[i])

print('%d %d' % (ans_n, ans_r))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
ma = max(a)
cnt = 10**9
mid = ma/2
for i in range(n):
    if abs(cnt - mid) >= abs(mid - a[i]):
        cnt = a[i]
print(max(ma,cnt),min(ma,cnt))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
l = a[-1]
def bigger(ind):
    global a, n, l
    if a[ind] > l / 2:
        return True
    else:
        return False
top = n
bottom = -1
while top - bottom > 1:
    mid = (top + bottom) // 2
    if bigger(mid):
        top = mid
    else:
        bottom = mid
if a[top] + a[bottom]> l or a[top] == l:
    print(l, a[bottom])
else:
    print(l, a[top])

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    l = max(a)
    r = 0
    chk = 10**9+1
    for x in a:
        if abs(x-l//2) < chk and x != l:
            r = x
            chk = abs(x-l//2)
    print(l, r)


if __name__ == "__main__":
    main()