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: Wrong Answer

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: Wrong Answer

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)
if abs(a[j-1] - key) > abs(a[j] - (key+1)) or not(j < n-1):
    ans = [a[i], a[j-1]]
else:
    ans = [a[i], a[j]]
# 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: Wrong Answer

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)
if abs(a[j-1] - key) > abs(a[j] - key) or not(j < n-1):
    ans = [a[i], a[j-1]]
else:
    ans = [a[i], a[j]]
# 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: Wrong Answer

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 abs(ans-a[0]/2)>abs(a[i+1]-a[0]/2):
        ans=a[i]
    # print(ans)
print(a[0],ans)

Submission status: Wrong Answer

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]
    # print(ans)
print(a[0],ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
N = int(input())
A = list(map(int, input().split()))
if N == 2:
    print(A[1], A[0])
    exit()
A.sort()
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: Wrong Answer

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


def comb(n, k):
    if k > n//2:
        k = n-k
    c, d = 1, 1
    for i in range(k):
        c *= n-i
        d *= i+1
    return c//d


ans = 0
s, t = 0, 0
for i in range(1, N):
    a = A[i]
    L = sorted([0]+A[:i+1])
    k = bisect_left(L, a//2+1)
    x = comb(a, L[k-1])
    y = comb(a, L[k])
    if x > ans:
        ans = x
        s, t = a, L[k-1]
    if y > ans:
        ans = y
        s, t = a, L[k]
print(s, t)

Submission status: Wrong Answer

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: Wrong Answer

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
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: Wrong Answer

Solution code:
import bisect

n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
keep = bisect.bisect(a, a[-1] / 2)
if a[keep] == a[-1]:
    keep -= 1
print(a[-1], a[keep])

Submission status: Wrong Answer

Solution code:
import bisect

n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
keep = bisect.bisect(a[:-1], a[-1] / 2)
if a[keep] == a[-1]:
    keep -= 1
print(a[-1], a[keep])

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
from bisect import bisect_left
N = int(input())
a = list(map(int,input().split()))
a.sort()
x = a[-1]
print(x, a[bisect_left(a, x//2, hi=N-2)])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
# n_C_rの最大化
# nは出来るだけ大きい方が良く、rは出来るだけn/2に近い方が良い
x = max(a)
y = float("inf")
for ai in a:
    if abs(x / 2 - ai) < abs(x / 2 - y):
        y = ai
print(x, y)

Submission status: Wrong Answer

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

max_a = max(a)

ans = max_a
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: Wrong Answer

Solution code:
from bisect import *
N = int(input())
A = sorted(list(map(int,input().split())))
print(A[-1],A[bisect_left(A,A[-1]/2)])

Submission status: Wrong Answer

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from scipy.special import comb
import bisect


def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    ans = [0, 0]
    chk = 0
    for i in range(n):
        for j in range(bisect.bisect_left(a, a[i]//2), bisect.bisect_right(a, a[i]//2+1)):
            tmp = max(comb(a[i], a[j], exact=True), comb(a[j], a[i], exact=True))
            if chk < tmp:
                chk = tmp
                ans[0] = max(a[j], a[i])
                ans[1] = min(a[j], a[i])
    print(*ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from scipy.special import comb
import bisect


def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    ans = [0, 0]
    chk = 0
    for i in range(n):
        for j in range(bisect.bisect_left(a, a[i]//2), bisect.bisect_right(a, a[i]//2+1)):
            tmp = max(comb(a[i], a[j], exact=True), comb(a[j], a[i], exact=True))
            if chk < tmp:
                chk = tmp
                ans[0] = a[j]
                ans[1] = a[i]
    print(*ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

if len(L) == 2:
    print(*L)
    exit()
    
maxL = L[-1]

from bisect import bisect,bisect_right,bisect_left

b = bisect_right(L,maxL//2)
c = bisect_left(L,maxL//2)

if maxL-L[b] >= maxL-L[c]:
    idx = b
else:
    idx = c

print(maxL,L[idx])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
r = a.pop(0)
s = r
temp = r
for i in range(n-1):
    if abs(r - 2*a[i]) < s:
        s = abs(r - 2*a[i])
        temp = a[i]
print(r, temp)

Submission status: Wrong Answer

Solution code:
import bisect

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

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

if idx != 0:
    if abs(A[idx - 1] - t) < abs(A[idx] - t):
        idx = idx - 1

print(' '.join([str(A[-1]), str(A[idx])]))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
if N==2:
    print(*A)
else:
    A=sorted(A)
    ans1=A[-1]
    del A[-1]
    saidai=ans1/2
    num=pow(10,9)
    for n in range(N-1):
        if abs(saidai-A[n])<=num:
            num=abs(saidai-A[n])
        else:
            ans2=n-1
    print(ans1,A[ans2])

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
if N==2:
    print(*A)
else:
    A=sorted(A)
    ans1=A[-1]
    del A[-1]
    saidai=ans1/2
    num=pow(10,9)
    for n in range(N-1):
        if abs(saidai-A[n])<num:
            num=abs(saidai-A[n])
        else:
            ans2=n-1
    print(ans1,A[ans2])

Submission status: Wrong Answer

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

n=max(a)

rc=float('inf')
rd=0
r=0
for i in a:
  if rc>abs(i-n/2):
    r=i
  rc=min(rc,abs(i-n/2))
  
print(n,r)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
n=int(input())
a=sorted(list(map(int,input().split())))
x=a[-1]
c=bisect_right(a,x//2)
if x%2==0:
    if x//2 in a:
        print("{} {}".format(x,x//2))
    else:
        if a[c]-x//2>=x//2-a[c-1]:
            print("{} {}".format(x,a[c-1]))
        else:
            print("{} {}".format(x,a[c]))

        
else:
    if x//2 in a :
        print("{} {}".format(x,x//2))
    elif x//2+1 in a:
        print("{} {}".format(x,x//2+1))
    else:
        if a[c]-x//2+1>=x//2-a[c-1]:
            print("{} {}".format(x,a[c-1]))
        else:
            print("{} {}".format(x,a[c]))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
n=int(input())
a=sorted(list(map(int,input().split())))
x=a[-1]
c=bisect_right(a,x//2)
if x%2==0:
    if x//2 in a:
        print("{} {}".format(x,x//2))
    else:
        if a[c]-x//2>=x//2-a[c-1]:
            print("{} {}".format(x,a[c-1]))
        else:
            print("{} {}".format(x,a[c-1]))

        
else:
    if x//2 in a :
        print("{} {}".format(x,x//2))
    elif x//2+1 in a:
        print("{} {}".format(x,x//2+1))
    else:
        if a[c]-x//2+1>=x//2-a[c-1]:
            print("{} {}".format(x,a[c-1]))
        else:
            print("{} {}".format(x,a[c-1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

m = max(lst)
r = m//2
k = float('inf')

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

Submission status: Wrong Answer

Solution code:
# import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
enu = enumerate
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

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

fact = [1]
for i in range(1, N + 10):
    fact.append(fact[-1] * i % MOD)


def rev(x):
    return pow(x, MOD - 2, MOD)


def cmb(i, k):
    if i < k:
        return 0
    return fact[i] * rev(fact[k]) * rev(fact[i - k]) % MOD


A.sort()
if N == 2:
    print(A[1], A[0])
    exit()

mv = A[-1]
vm = mv // 2
bli = bisect_left(A, vm)
if bli == N - 1:
    print(mv, A[bli - 1])
elif bli == 0:
    print(mv, A[bli])
else:
    if vm - A[bli - 1] <= A[bli] - vm:
        print(mv, A[bli - 1])
    else:
        print(mv, A[bli])

Submission status: Wrong Answer

Solution code:
# import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
enu = enumerate
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

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

fact = [1]
for i in range(1, N + 10):
    fact.append(fact[-1] * i % MOD)


def rev(x):
    return pow(x, MOD - 2, MOD)


def cmb(i, k):
    if i < k:
        return 0
    return fact[i] * rev(fact[k]) * rev(fact[i - k]) % MOD


A.sort()
if N == 2:
    print(A[1], A[0])
    exit()

mv = A[-1]
vm = mv // 2
bli = bisect_left(A, vm)
if bli == N - 1:
    print(mv, A[bli - 1])
else:
    print(mv, A[bli])

Submission status: Wrong Answer

Solution code:
# import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
enu = enumerate
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

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

fact = [1]
for i in range(1, N + 10):
    fact.append(fact[-1] * i % MOD)


def rev(x):
    return pow(x, MOD - 2, MOD)


def cmb(i, k):
    if i < k:
        return 0
    return fact[i] * rev(fact[k]) * rev(fact[i - k]) % MOD


A.sort()
if N == 2:
    print(A[1], A[0])
    exit()

mv = max(A)
vm = mv // 2
bli = bisect_left(A, vm)
if bli == N - 1:
    print(mv, A[bli - 1])
else:
    print(mv, A[bli])

Submission status: Wrong Answer

Solution code:

from bisect import bisect_left,bisect

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

a.sort()
ai=max(a)


if ai%2==0:
    ai2=ai//2+1
else:
    ai2=ai//2

jj=bisect(a,ai2)

if jj+1<n:
    if abs(a[jj]-ai2)>abs(a[jj+1]-ai2):
        jj=jj+1
if jj-1>=0:
    if abs(a[jj]-ai2)>abs(a[jj-1]-ai2):
        jj=jj-1
    
if jj==n-1:
    jj=jj-1
    
aj=a[jj]

print(ai,aj)

Submission status: Wrong Answer

Solution code:

from bisect import bisect_left,bisect

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

a.sort()
ai=max(a)


if ai%2==0:
    ai2=ai//2-1
else:
    ai2=ai//2

jj=bisect(a,ai2)
#jj=bisect(a,n//2)
if jj+1<n:
    if abs(a[jj]-ai2)>abs(a[jj+1]-ai2):
        jj=jj+1
if jj-1>=0:
    if abs(a[jj]-ai2)>abs(a[jj-1]-ai2):
        jj=jj-1
    
if jj==n-1:
    jj=jj-1
    
aj=a[jj]

print(ai,aj)

Submission status: Wrong Answer

Solution code:

from bisect import bisect_left,bisect

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

a.sort()
ai=max(a)


if ai%2==0:
    ai2=ai//2-1
else:
    ai2=ai//2

jj=bisect(a,ai2)

if jj==n-1:
    jj=jj-1
    
aj=a[jj]

print(ai,aj)

Submission status: Wrong Answer

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

a.sort()
ai=max(a)
if n%2==0:
    jj=n//2-1
else:
    jj=n//2
aj=a[jj]

print(ai,aj)

Submission status: Wrong Answer

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

a.sort()
ai=max(a)
aj=a[n//2]

print(ai,aj)

Submission status: Wrong Answer

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

import bisect

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

a.sort()

if n == 2:
    print(a[1], a[0])
    exit()
# value = comb(a[1], a[0], exact=True)
# ans = [a[1], a[0]]
# index = 0
# for i in range(2, n):
#     value_tmp = comb(a[i], a[index], exact=True)
#     x = a[i]
#     y = a[index]
#     diff = abs((x-2*y)//2)
#     while 1:
#         y_new = a[index+1]
#         diff_new = abs((x-2*y_new)//2)
#         if diff_new > diff:
#             break
#         else:
#             index += 1
#     if value_tmp > value:
#         ans = [a[i], a[index]]
#         # value = value_tmp
# print(*ans)

x = a[-1]
index = bisect.bisect_left(a[:n-1], x/2)

ans = []
# ans.append([abs(x/2-a[index-1]), a[index-1]])
ans.append([abs(x/2-a[index]), a[index]])
ans.append([abs(x/2-a[index+1]), a[index+1]])

ans.sort()

print(x, ans[0][1])

Submission status: Wrong Answer

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

import bisect

n = int(input())
a = [i*2 for i in list(map(int, input().split()))]

a.sort()

if n == 2:
    print(a[1]//2, a[0]//2)
    exit()
# value = comb(a[1], a[0], exact=True)
# ans = [a[1], a[0]]
# index = 0
# for i in range(2, n):
#     value_tmp = comb(a[i], a[index], exact=True)
#     x = a[i]
#     y = a[index]
#     diff = abs((x-2*y)//2)
#     while 1:
#         y_new = a[index+1]
#         diff_new = abs((x-2*y_new)//2)
#         if diff_new > diff:
#             break
#         else:
#             index += 1
#     if value_tmp > value:
#         ans = [a[i], a[index]]
#         # value = value_tmp
# print(*ans)

x = a[-1]
index = bisect.bisect_left(a[:-1], x/2)

# print(index)
diff0 = abs(x-a[index-1])
diff1 = abs(x-a[index])
diff2 = abs(x-a[index+1])

if diff1 > diff2:
    print(x//2, a[index]//2)
else:
    print(x//2, a[index+1]//2)

Submission status: Wrong Answer

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

import bisect

n = int(input())
a = [i*2 for i in list(map(int, input().split()))]

a.sort()

if n == 2:
    print(a[1]//2, a[0]//2)
    exit()
# value = comb(a[1], a[0], exact=True)
# ans = [a[1], a[0]]
# index = 0
# for i in range(2, n):
#     value_tmp = comb(a[i], a[index], exact=True)
#     x = a[i]
#     y = a[index]
#     diff = abs((x-2*y)//2)
#     while 1:
#         y_new = a[index+1]
#         diff_new = abs((x-2*y_new)//2)
#         if diff_new > diff:
#             break
#         else:
#             index += 1
#     if value_tmp > value:
#         ans = [a[i], a[index]]
#         # value = value_tmp
# print(*ans)

x = a[-1]
index = bisect.bisect_left(a[:-1], x//2)

# print(index)
diff1 = abs(x-a[index])
diff2 = abs(x-a[index+1])

if diff1 > diff2:
    print(x//2, a[index]//2)
else:
    print(x//2, a[index+1]//2)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(map(int, input().split()))
p = a[-1]
b =10000000
c = 0
for i in range(n-1):
  if abs(a[i]-p/2) < b:
    b = abs(a[i]-p/2)
    c = a[i]
  else:
    break
print(p,c)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(map(int, input().split()))
p = a[-1]
b =100000
c = 0
for i in range(n-1):
  if abs(a[i]-p/2) < b:
    b = abs(a[i]-p/2)
    c = a[i]
print(str(p)+' '+str(c))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(map(int, input().split()))
p = a[-1]
if p%2==1:
  q = p//2+1
else:
  q = p//2+0.5
b =100000
c = 0
for i in range(n-1):
  if abs(a[i]-q) < b:
    b = abs(a[i]-q)
    c = a[i]
print(str(p)+' '+str(c))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
p = max(a)
if p%2==1:
  q = p//2+1
else:
  q = p//2+0.5
b =100000
c = 0
for i in range(n):
  if abs(a[i]-q) < b:
    b = abs(a[i]-q)
    c = a[i]
print(str(p)+' '+str(c))

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int,input().split()))
L .sort()
maxL = L[-1]

from bisect import bisect

if n%2 == 0:
    num = maxL//2
else:
    num = maxL//2+1
#
idx = bisect(L,num)

print(maxL,L[idx-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
maxa = max(a)
mini = [[] for _ in range(n)]
for i, v in enumerate(a):
    r = maxa - v
    mini[i] = [v, abs(v - r)]
mini.sort(key=lambda x: x[1])
print(maxa, mini[0][0])

Submission status: Wrong Answer

Solution code:
from scipy.special import comb

_ = int(input())
a = sorted(list(map(int, input().split())))
ans, num, val = 0, a[-1], 0

for i in a[:-1]:
    num1 = comb(num, i)
    if num1 > val:
        val = num1
        ans = i
print(num, ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    import bisect
    N = int(input())
    A = sorted([int(i) for i in input().split()])
    if N == 2:
        print(max(A), min(A))
        return
    maxA = A[-1]
    half = maxA / 2
    i = bisect.bisect_left(A, half)
    if half - A[i] < A[i + 1] - half:
        print(maxA, A[i])
    else:
        print(maxA, A[i + 1])


resolve()

Submission status: Wrong Answer

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

A_max = max(A)

X = [abs(a-(A_max//2)) for a in A]

X_min_id = X.index(min(X))

print(A_max,A[X_min_id])

Submission status: Wrong Answer

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

A.sort()
x = A[-1]
A.pop()

z = x

for a in A:
    if abs(x-a*2) < abs(x-z*2):
        z = a

print(x, z)

Submission status: Wrong Answer

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

A.sort()
x = A[-1]
A.pop()

y = x/2
z = x

for a in A:
    if abs(y-a) < abs(y-z):
        z = a

print(x, z)

Submission status: Wrong Answer

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

A.sort()
x = A[-1]
A.pop()

y = x/2
z = x

for a in A:
    if abs(y-a) < abs(z-a):
        z = a

print(x, z)

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    A.sort()
    n = max(A)

    i = 0
    while i < N - 1 and 2 * A[i] < n:
        i += 1

    if i in (0, N - 1):
        r = A[i]
    elif abs(2 * A[i] - n) < abs(2 * A[i - 1] - n):
        r = A[i]
    else:
        r = A[i - 1]

    print(n, r)
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

n = max(A)
mid = n / 2
r = float("inf")
for a in A:
    if abs(mid - r) > abs(mid - a):
        r = a

print(n, r)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50

def run():
    n = int(sysread())
    A = list(map(int, sysread().split()))
    #print(A)
    A = sorted(A)
    #print(n, A)
    idx = bisect.bisect_left(A, A[-1] / 2)
    if idx == 0:
        print(f'{A[-1]} {A[0]}')
    else:
        val1 = A[idx]
        val2 = A[idx-1]
        if abs(val1 - A[-1] / 2) > abs(val2 - A[-1] / 2):
            print(f'{A[-1]} {val2}')
        else:
            print(f'{A[-1]} {val1}')


if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50

def run():
    n = int(sysread())
    A = list(map(int, sysread().split()))
    #print(A)
    A = sorted(A)
    #print(n, A)
    idx = bisect.bisect_left(A, A[-1] / 2)
    if idx == 0:
        print(f'{A[-1]} {A[0]}')
    else:
        val1 = A[idx]
        val2 = A[idx-1]
        if abs(val1 - A[-1]) / 2 > abs(val2 - A[-1]) / 2:
            print(f'{A[-1]} {val2}')
        else:
            print(f'{A[-1]} {val1}')


if __name__ == "__main__":
    run()

Submission status: Wrong Answer

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

a = a[:-1]
y = bisect.bisect_left(a,y)
if len(a) <= y: y -= 1
print(x,a[y])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
x = a[-1]
y = max(a)//2
a = a[:-1]
while y < x:
    y += 1
    if y in a: break
    if x-y in a:
        y = x-y
        break
print(x,y)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
sa = set(A)
n = max(A)

if n%2==0 and n//2 in sa:
    print(n, n//2)
    exit()

if n%2:
    i,j = n//2, n//2+1
else:
    i,j = n//2-1, n//2+1

while i >= 0:
    if i in sa:
        print(n, i)
        exit()
    if j in sa:
        print(n, j)
        exit()
    i -= 1
    j -= 1

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
ma = max(a)
a.remove(ma)
num = 0
ind = 0
a.sort()
for i in range(N-1):
    if a[i] < ma//2:
        ind += 1

if ind == 0:
    print(ma,a[0])
    exit()
elif ind == N-1:
    print(ma,a[-1])
    exit()

if abs(ma - a[ind-1]) < abs(ma - a[ind]):
    print(ma,a[ind-1])
else:
    print(ma,a[ind])

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
ma = max(a)
a.remove(ma)
num = 0
ind = 0
a.sort()
for i in range(N-1):
    if a[i] > ma//2:
        ind += 1

if ind == 0:
    print(ma,a[0])
    exit()
elif ind == N:
    print(ma,a[-1])
    exit()

if abs(ma - a[ind-1]) < abs(ma - a[ind]):
    print(ma,a[ind-1])
else:
    print(ma,a[ind])

Submission status: Wrong Answer

Solution code:
from scipy.special import comb

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

# N=2の時は組み合わせは1つしかない
if N == 2:
    print(A[0], A[1])
    exit(0)


A.sort()
n = A[-1]
mid = n//2
idx = 0
for i in range(N-1):
    if abs(A[i]-mid) >= abs(A[i+1]-mid):
        idx = i+1
        break

cmb = comb(n, A[idx], exact=True)
cmb_h = comb(n, A[idx+1], exact=True)
cmb_l = 0
if idx > 0:
    cmb_l = comb(n, A[idx-1], exact=True)

max_cmb = max(cmb, cmb_l, cmb_h)
if cmb == max_cmb:
    print(n, A[idx])
elif cmb_l == max_cmb:
    print(n, A[idx-1])
else:
    print(n, A[idx+1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]+sorted(list(map(int,input().split())))
x=a[-1]
m=a[-1]
for i in a:
  if m>abs(i-x):y=i
print(x,y)

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
a=[0]+sorted(list(map(int,input().split())))
x=a[-1]
i=bisect.bisect_left(a,x//2)
if abs(a[i]-x)>=abs(a[i-1]-x)+1:y=a[i-1]
else:y=a[i]
print(x,y)

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
a=[0]+sorted(list(map(int,input().split())))
x=a[-1]
i=bisect.bisect_left(a,x//2)
if abs(a[i]-x)>abs(a[i-1]-x):y=a[i-1]
elif i==n:y=a[i-1]
else:y=a[i]
print(x,y)

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
a=[0]+sorted(list(map(int,input().split())))
x=a[-1]
i=bisect.bisect_left(a,x//2)
y=[a[i-1],a[i]][abs(a[i]-x)<abs(a[i-1]-x)]
print(x,y)

Submission status: Wrong Answer

Solution code:
n = int(input())
aa = list(map(int, input().split()))
x = max(aa)
y = aa[0]
if y == aa[0]:
    y = aa[1]
for i in range(n):
    if y == aa[i]:
        continue
    if abs(x / 2 - y) > abs(y / 2 - aa[i]):
        y = aa[i]
print("{} {}".format(x, y))

Submission status: Wrong Answer

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

ai = a[-1]
half_ai = ai // 2

i_left = bisect.bisect_left(a, half_ai)
i_right = bisect.bisect_right(a, half_ai)
if (a[i_left] == half_ai):
    print(ai, half_ai)
    exit()

if (i_left == i_right and i_left == 0):
    print(ai, a[0])
    exit()

if (ai - a[i_left - 1] >= ai - a[i_right] and i_right != len(a) - 1):
    print(ai, a[i_right])
else:
    print(ai, a[i_left - 1])

Submission status: Wrong Answer

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

ai = a[-1]
half_ai = ai // 2

i_left = bisect.bisect_left(a, half_ai)
i_right = bisect.bisect_right(a, half_ai)
if (a[i_left] == half_ai):
    print(ai, half_ai)
    exit()

if (ai - a[i_left - 1] >= ai - a[i_right] and i_right != len(a) - 1):
    print(ai, a[i_right])
else:
    print(ai, a[i_left - 1])

Submission status: Wrong Answer

Solution code:
import math
import itertools

def swap(a,b):
    return max(a,b),min(a,b)

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

N = int(input())
an = list(map(int,input().split()))
target = an[-1]/2
res = min(enumerate(an), key=lambda x: abs(target - x[1]))
print(an[-1], res[1])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
#print(a)
h=a[0]/2
dif=10**18
tmp=None
for i in range(n):
    if dif>abs(a[i]-h):
        dif=abs(a[i]-h)
        tmp=a[i]
print(a[0],tmp)