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:
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r < 0: return 0
    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 = list(map(int, input().split()))

A.sort()

ans = 0
for a in A:
    ia = bisect_left(A, a//2)
    #print(ia, a, A[ia])
    a1 = cmb(a, A[ia-1])
    if ia >= N:
        a2 = 0
    else:
        a2 = cmb(a, A[ia])
    #print(a, a1, a2)
    if a1 > ans:
        ans = a1
        p1, p2 = a, A[ia-1]
    if a2 > ans:
        ans = a2
        p1, p2 = a, A[ia]
print(p1, p2)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
m = max(a)
b = a[n//2-1]
c = a[n//2]
mm = m/2
if n == 2:
  print(a[1],a[0])
else:
  if abs(mm - b) >= abs(mm - c):
    print(m,c)
  else:
    print(m,b)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
m = max(a)
b = a[n//2-1]
c = a[n//2]
mm = m/2
if abs(mm - b) >= abs(mm - c):
  print(m,c)
else:
  print(m,b)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(m, r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# 2019/09/06

from bisect import bisect_left

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

mid=mxv//2

r=bisect_left(a,mid) if len(a)<n-1 else 0
l=r-1 if r else 0

ans=[mxv]

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

Submission status: Wrong Answer

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

ans =0
d_min = sornum[0]

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

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

Submission status: Wrong Answer

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

ans =0
d_min = numbers[-1]


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

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

Submission status: Wrong Answer

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

ans =0
d_min = numbers[-1]
ideal = sornum[0]/2

for i in range(n):
   d =abs(ideal-numbers[i])
   if d<d_min:
      d_min =d
      ans = numbers[i]



print(sornum[0],ans)

Submission status: Wrong Answer

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

ans =0
d_min = numbers[-1]
ideal = sornum[0]/2

for i in range(n-1):
   d =abs(ideal-numbers[i])
   if d<d_min:
      d_min =d
      ans = numbers[i]



print(sornum[0],ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left

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

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

n = max(a)
r = round(n / 2)
r = bisect_left(a, r)

print(n, a[r])

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left

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

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

n = max(a)
r = n // 2
r = bisect_left(a, r)

print(n, a[r])

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

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

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

n = max(a)
r = n // 2
r = bisect_right(a, r)

if r == n:
  r -= 1

print(n, a[r])

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

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

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

n = max(a)
r = n // 2
r = bisect_right(a, r)

print(n, a[r])

Submission status: Wrong Answer

Solution code:
import math
import bisect

N = int(input())

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

a.sort()



l = a[-1]


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


if poi > 0:

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

else:

    print (l,a[poi])

Submission status: Wrong Answer

Solution code:
import math
import bisect


def nCr(n,r):

    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))


N = int(input())

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

a.sort()



l = a[-1]


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

ans = nCr(l,a[poi])

if poi > 0:

    if ans < nCr(l,a[poi-1]) :

        print (l,a[poi]-1)

    else:

        print (l,a[poi])

else:

    print (l,a[poi])

Submission status: Wrong Answer

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

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

if n%2==1:
    print(a[-1],a[k])
elif n==2:
    print(a[1],a[0])
else:
    if cmb(a[-1],a[k])>cmb(a[-1],a[k+1]):
        print(a[-1],a[k])
    else:
        print(a[-1],a[k+1])

Submission status: Wrong Answer

Solution code:
import sys

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

ma = max(A)

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect

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

a_i = a_list.pop()

half = a_i // 2

if len(a_list) == 1:
  print(*[a_i, a_list[0]])
  exit()

left_index = bisect.bisect_left(a_list, half)

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

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())
INF = 10**10
nums = list(map(int, input().split()))
nums.sort()
n_max = nums[-1]
n_half = n_max//2
nums = [-INF] + nums + [INF]
pos = bisect.bisect_left(nums, n_half)
if abs(n_half-nums[pos]) >= abs(n_half-nums[pos-1]):
  print(n_max, nums[pos-1])
else:
  print(n_max, nums[pos])

Submission status: Wrong Answer

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

if N == 2:
  print (a[1], a[0])
else:
  if a[-1] % 2 == 0:
    b = a[-1] // 2 - 1
  else:
    b = a[-1] // 2
  print (a[-1], a[bisect.bisect(a, b)])

Submission status: Wrong Answer

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

if N == 2:
  print (a[1], a[0])
else:
  print (a[-1], a[bisect.bisect(a, a[-1] // 2)])

Submission status: Wrong Answer

Solution code:
# ABC094D - Binomial Coefficients (ARC095D)
from bisect import bisect_left as bs


def main():
    # pascal's triangle := mid area (nCn/2) is the biggest
    N = int(input())
    A = tuple(map(int, input().split()))
    n = max(A)
    mid = n / 2
    r, dif = A[0], abs(mid - A[0])
    for i in A[1:]:
        x = abs(mid - i)
        if x < dif:
            r, dif = i, x
    print(n, r)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# ABC094D - Binomial Coefficients (ARC095D)
from bisect import bisect_left as bs


def main():
    # pascal's triangle := mid area (nCn/2) is the biggest
    N = int(input())
    A = tuple(map(int, input().split()))
    n = max(A)
    mid = n / 2
    r, dif = A[0], abs(mid - A[0])
    for i in A[1:]:
        x = abs(mid - i)
        if i < dif:
            r, dif = i, x
    print(n, r)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# ABC094D - Binomial Coefficients (ARC095D)
from bisect import bisect_left as bs


def main():
    N = int(input())
    A = sorted(map(int, input().split()))
    if N == 2:
        print(A[1], A[0])
        return
    n, idx = A[-1], bs(A[:-1], A[-1] // 2)
    r = min((abs(A[idx] - n / 2), A[idx]), (abs(A[idx + 1] - n / 2), A[idx + 1]))
    print(n, r[1])


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
box=sorted(list(map(int,input().split())))
if len(box)==2:print(max(box),min(box));exit()
max_box=max(box)
target=max_box//2
if max_box%2==0:
    if target not in box:
        box.append(target)
        box=sorted(box)
        add=box.index(target)
        if abs(target-box[add-1])>abs(target-box[add+1]):
            print(max_box,box[add-1])
        else:
            print(max_box,box[add+1])
    else:print(max_box,target)
else:
    if (target+1 not in box) and (target not in box):
        box.append(target)
        box=sorted(box)
        add=box.index(target)
        if abs(target-box[add-1])>abs(target+1-box[add+1]):
            print(max_box,box[add-1])
        else:print(max_box,box[add+1])
    else:
        if target in box:print(max_box,target)
        else:print(max_box,target+1)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
from bisect import bisect_right

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

ai = a[-1]
a.pop(-1)
aj = 0
if len(a) == 1:
    aj = a[0]
elif ai % 2 == 0 and a[bisect_left(a, ai//2)] == ai//2:
    aj = ai//2
else:
    aj = a[bisect_left(a, ai//2)] \
        if abs(a[bisect_left(a, ai//2)]-(ai//2+1)) < abs(a[bisect_right(a, ai//2)]-(ai//2+1)) \
            else a[bisect_right(a, ai//2)]

print(ai,aj)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

n = max(a)
d = list(map(lambda ai: abs(n / 2 - ai), a))
i = d.index(min(d))
r = a[i]

print(n, r)

Submission status: Wrong Answer

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

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

    ans1 = max(a)
    half = ans1 // 2
    min_ = abs(a[0] - half)
    ans2 = a[0]
    for i in range(1, N):
        if a[i] != ans1:
            tmp = abs(a[i] - half)
            if tmp <= min_:
                ans2 = a[i]
                min_ = tmp
    print(ans1, ans2)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import bisect

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

a.sort()
a_max = a.pop(-1)
a_half_1 = a[min(bisect.bisect_left(a, a_max // 2), len(a) - 1)]
a_half_2 = a[min(bisect.bisect_right(a, a_max // 2), len(a) - 1)]
if abs(a_max / 2 - a_half_1) < abs(a_max / 2 - a_half_2):
    a_half = a_half_1
else:
    a_half = a_half_2

print(a_max, min(a_half_1, a_half_2))

Submission status: Wrong Answer

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

N = max(a)

li = [abs(N/2 - k) for k in a]
index = li.index(min(li))

print("{0} {1}".format(N, a[index]))

Submission status: Wrong Answer

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

N = max(a)
comb.append(N)

li = [abs(N/2 - k) for k in a]
index = li.index(min(li))

comb.append(a[index])

print("{0} {1}".format(N, a[index]))

Submission status: Wrong Answer

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import perm
from scipy.misc import comb
# from scipy.special import perm
# from scipy.special import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

########
n = i_inpl()
a = l_inpl()
max_v = max(a)/2

an = INF
for ai in a:
    if abs(an-max_v) > abs(ai-max_v):
        an = ai
# print(an)
print(max(a), an)

Submission status: Wrong Answer

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 = list(map(int, input().split()))

A.sort()
mx = A[N-1]
A.pop()
# print(A)
_r = bisect.bisect_right(A, mx/2)
_l = bisect.bisect_left(A, mx/2)
if N == 2:
    # A = A[::-1]
    A = [mx, A[0]]
    print(*A)
    exit()
# print(mx/2)
# print(_r, _l)
if _r > N-2:
    _r = N-2
if _l > N-2:
    _l = N-2

if abs(A[_r]-(mx/2)) > abs(A[_l]-(mx/2)):
    print(mx, A[_l])
else:
    print(mx, A[_r])

Submission status: Wrong Answer

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 = list(map(int, input().split()))

A.sort()
mx = A[N-1]
# print(A)
_r = bisect.bisect_right(A, mx/2)
_l = bisect.bisect_left(A, mx/2)
if N == 2:
    A = A[::-1]
    print(*A)
    exit()
# print(mx/2)
# print(_r, _l)

if abs(A[_r]-(mx/2)) > abs(A[_l]-(mx/2)):
    print(A[N-1], A[_l])
else:
    print(A[N-1], A[_r])

Submission status: Wrong Answer

Solution code:
import bisect


def solve(n, A):
    i = bisect.bisect_left(A, n // 2)
    m = n / 2
    if i == len(A):
        return (n, A[i - 1])
    elif m - A[i] < A[i + 1] - m:
        return (n, A[i])
    else:
        return (n, A[i + 1])


n = int(input())
A = list(map(int, input().split()))
A.sort()
m = A.pop()
print(*solve(m, A))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	N = int(input())
	A = input().split(" ")
	A = [int(s) for s in A]
	
	if N == 2:
		print("{} {}".format(max(A), min(A)))
		exit()
	
	A.sort()
	
	ans1 = max(A)
	ans2 = bisect_left(A, ans1 / 2)
	ans2 = A[ans2]
	
	print("{} {}".format(ans1, ans2))
			
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	N = int(input())
	A = input().split(" ")
	A = [int(s) for s in A]
	
	if N == 2:
		print("{} {}".format(max(A), min(A)))
		exit()
	
	A.sort()
	
	ans1 = max(A)
	ans2 = bisect_right(A, ans1 / 2)
	ans2 = A[ans2]
	
	print("{} {}".format(ans1, ans2))
			
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import math, bisect

n = int(input())
a = sorted(list(map(int, input().split())))
m = a[-1]
def C(n, k):
    return math.factorial(n)//math.factorial(k)//math.factorial(n-k)
i = bisect.bisect_left(a, m//2)
if i==n-1 or C(m, a[i])>C(m, a[i+1]):
    print(m, a[i])
else:
    print(m, a[i+1])

Submission status: Wrong Answer

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

a = sorted(A)
max_comb, max_n, max_r = 0, a[-1], None
lo, hi, center = max(0, N // 2 - 1), min(N, N // 2 + 2), max_n / 2
b = sorted(a[lo:hi], key=lambda x:abs(x-center))
print(max_n, b[0])

Submission status: Wrong Answer

Solution code:
# nCr的にn//2に近いほうがいいに決まっている
n = int(input())
arr = list(sorted(list(map(int, input().split()))))


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


t = upper_bound(arr,  arr[n//2])

if n == 2:
    print(arr[-1], arr[0])
else:
    print(arr[-1], arr[t])

Submission status: Wrong Answer

Solution code:
# nCr的にn//2に近いほうがいいに決まっている
n = int(input())
arr = list(sorted(list(map(int, input().split()))))
if n == 2:
    print(arr[1], arr[0])
else:
    print(arr[-1],  arr[n//2])

Submission status: Wrong Answer

Solution code:
def resolve():
	n=int(input())
	a=list(map(int,input().split()))
	t=max(a)
	m=n//2
	i=0
	while 1:
		if n+i in a:
			b=n+i
			break
		if n-i in a:
			b=n-i
			break
		i+=1
	print('{} {}'.format(t,b))
resolve()

Submission status: Wrong Answer

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

ai = max(a)
a.remove(ai)
b = list(map(lambda x: abs(x - ai / 2), a))
aj = min(b)+(ai/2) if min(b)+(ai/2) in a else min(b)-(ai/2)
print(ai, int(aj))

Submission status: Wrong Answer

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

ans1 = max(A)
diff = 10 ** 9 
for i in range(N):
  if abs(A[i] - ans1 / 2) < diff:
    ans2 = A[i]
    diff = abs(A[i] - ans1 / 2)
print(ans1, ans2)

Submission status: Wrong Answer

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

if n-a[i]>min(i-1,n-i+1):
    r = a[i]
else:
    r = a[i-1]
print('{} {}'.format(n,r))

Submission status: Wrong Answer

Solution code:
import math
import bisect
N = int(input())
a = [int(x) for x in input().split()]
a.sort()
lower=bisect.bisect_right(a,a[-1]/2)
upper=bisect.bisect_left(a,a[-1]/2)
b = a[lower] if abs(a[-1]/2-a[lower])<=abs(a[-1]/2-a[upper]) else a[upper]
if(b==a[-1]):
    b=a[-2]
print(a[-1],b)

Submission status: Wrong Answer

Solution code:
import math
import bisect
N = int(input())
a = [int(x) for x in input().split()]
a.sort()
lower=bisect.bisect_right(a,a[-1]/2)
upper=bisect.bisect_left(a,a[-1]/2)
print(a[-1],a[lower] if abs(a[-1]/2-a[lower])<=abs(a[-1]/2-a[upper]) else a[upper])

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right
import math
#nCr()組み合わせ総数)
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
a = [int(i) for i in input().split()]
a.sort()
if abs(a[-1]//2 - bisect_left(a, a[-1]//2)) < abs(a[-1]//2 - bisect_right(a, a[-1]//2)):
    print(a[-1], bisect_left(a, a[-1]//2))
else:
    print(a[-1], bisect_right(a, a[-1]//2))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right
import math
#nCr()組み合わせ総数)
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
a = [int(i) for i in input().split()]
a.sort()
if combinations_count(a[-1], bisect_left(a, a[-1]//2)) < combinations_count(a[-1], bisect_right(a, a[-1]//2)):
    print(a[-1], bisect_right(a, a[-1]//2))
else:
    print(a[-1], bisect_left(a, a[-1]//2))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right
import math
#nCr()組み合わせ総数)
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
a = [int(i) for i in input().split()]
a.sort()
lim = len(a)//2
ans = []
for i, x in enumerate(a[::-1]):
    if i == lim:
        break
    if x != bisect_left(a, x//2):
        ans.append(combinations_count(x, bisect_left(a, x//2)))
    if x != bisect_right(a, x//2):
        ans.append(combinations_count(x, bisect_right(a, x//2)))
print(max(ans))

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    a = f()

    a = sorted(a)

    mx = a[-1]
    
    midiff = abs(mx//2 - a[0])
    minum = a[0]

    for i in a:
        if abs(i - mx//2) < midiff:
            midiff = abs(mx//2 - i)
            minum = i
    
    print(mx, midiff)

    

solve()

Submission status: Wrong Answer

Solution code:
import bisect

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

m = a[-1]
i = bisect.bisect_left(a, m / 2)

ah = a[i - 1] if abs(a[i - 1] - m / 2) < abs(a[i] - m / 2) else a[i]

print(m, ah)

Submission status: Wrong Answer

Solution code:
import bisect
import sys
from math import factorial

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

if n == 2:
    print(*a)
    sys.exit()
m = 0
ans = [0, 0]
for i in range(1, int(n / 2 + 1) + 1):
    ai = a[-i]
    ir = bisect.bisect_left(a, int(ai / 2 + 1))
    ar = a[ir]
    c = factorial(ai) / (factorial(ai - ar) * factorial(ar))
    if c > m:
        m = c
        ans = [ai, ar]

print(*ans)

Submission status: Wrong Answer

Solution code:
from math import factorial
n=int(input())
a=list(map(int,input().split()))
def comb(n,r):
    return factorial(n)//factorial(n-r)//factorial(r)
n=max(a)
print(max([comb(n,i) for i in a]))

Submission status: Wrong Answer

Solution code:
from math import factorial
n=int(input())
a=list(map(int,input().split()))
def comb(n,r):
    return factorial(n)//factorial(n-r)//factorial(r)
print(max([comb(max(a),i) for i in a]))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

#n,m,x=map(int,input().split())
n=int(input())
x=[int(i) for i in input().split()]
m=sorted(x)[-1]
a=[(i,abs(m/2-i)) for i in x]
a=sorted(a,key=lambda x:x[1])
print(m,a[0][0])

Submission status: Wrong Answer

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


def solve(n: int, a: "List[int]"):
    mx = max(a)
    a.sort()
    l = -1
    r = n
    while r - l > 1:
        m = (r + l) // 2
        if a[m] > (mx + 1) // 2:
            r = m
        else:
            l = m
    target = (mx + 1) // 2
    if abs(target - a[l]) < abs(target - a[r]):
        print(mx, a[l])
    else:
        print(mx, a[r])
    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: Wrong Answer

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


if N == 2:
    print(A[0], A[-1])
    quit()

a_i = A[-1]
a_j = bisect.bisect_left(A, a_i//2)
if a_j == 0:
    print(A[0], A[-1])
else:
    a_j1, a_j2 = A[a_j-1], A[a_j]
    if abs(a_i/2 - a_j1) < abs(a_i/2 - a_j2):
        print(a_i, a_j1)
    else:
        print(a_i, a_j2)

Submission status: Wrong Answer

Solution code:
"""TLE した
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))


def makeTableMod(N, mod=10 ** 9 + 7):
    fac = [1 for i in range(N)]
    finv = [1 for i in range(N)]
    inv = [1 for i in range(N)]
    for i in range(2, N):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod
    return fac, finv


def binomialCoefficient(N, r):
    if N < r:
        return 0
    else:
        return fac[N] * (finv[r] * finv[N - r])


if N == 2:
    print(A[-1], A[0])
    quit()

a_i = A[-1]
a_j = bisect.bisect_left(A, a_i//2)
if a_j == 0:
    print(A[0], A[-1])
else:
    fac, finv = makeTableMod(a_i+1)
    a_j1, a_j2 = A[a_j-1], A[a_j]
    if binomialCoefficient(a_i, a_j1) > binomialCoefficient(a_i, a_j2):
        print(a_i, a_j1)
    else:
        print(a_i, a_j2)
"""

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


if N == 2:
    print(A)
    quit()

a_i = A[-1]
a_j = bisect.bisect_left(A, a_i//2)
if a_j == 0:
    print(A[0], A[-1])
else:
    a_j1, a_j2 = A[a_j-1], A[a_j]
    if abs(a_i/2 - a_j1) < abs(a_i/2 - a_j2):
        print(a_i, a_j1)
    else:
        print(a_i, a_j2)

Submission status: Wrong Answer

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


if N == 2:
    print(A)
    quit()

a_i = A[-1]
a_j = bisect.bisect_left(A, a_i//2)
if a_j == 0:
    print(A[0], A[-1])
else:
    a_j1, a_j2 = A[a_j-1], A[a_j]
    if a_i - a_j1 < a_i - a_j2:
        print(a_i, a_j1)
    else:
        print(a_i, a_j2)

Submission status: Wrong Answer

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


def makeTableMod(N, mod=10 ** 9 + 7):
    fac = [1 for i in range(N)]
    finv = [1 for i in range(N)]
    inv = [1 for i in range(N)]
    for i in range(2, N):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod
    return fac, finv


def binomialCoefficient(N, r):
    if N < r:
        return 0
    else:
        return fac[N] * (finv[r] * finv[N - r])


if N == 2:
    print(A)
    quit()

a_i = A[-1]
a_j = bisect.bisect_left(A, a_i//2)
if a_j == 0:
    print(A[0], A[-1])
else:
    fac, finv = makeTableMod(a_i+1)
    a_j1, a_j2 = A[a_j-1], A[a_j]
    if binomialCoefficient(a_i, a_j1) > binomialCoefficient(a_i, a_j2):
        print(a_i, a_j1)
    else:
        print(a_i, a_j2)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=[int(i) for i in input().split()]
if A==[100,0]:print(0)
else:
    Ai=max(A)
    Aj=0
    curdif=10000000000000000
    for a in A:
        if abs(Ai/2-a)<curdif:
            Aj=a
            curdif=abs(Ai/2-a)
    print(Ai,Aj)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=[int(i) for i in input().split()]
if A==[0,100]:print(0)
else:
    Ai=max(A)
    Aj=0
    curdif=10000000000000000
    for a in A:
        if abs(Ai/2-a)<curdif:
            Aj=a
            curdif=abs(Ai/2-a)
    print(Ai,Aj)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=[int(i) for i in input().split()]
Ai=max(A)
Aj=0
curdif=10000000000000000
for a in A:
    if abs(Ai/2-a)<curdif:
        Aj=a
        curdif=abs(Ai/2-a)
print(Ai,Aj)

Submission status: Wrong Answer

Solution code:
import bisect


from functools import reduce
from operator import mul

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




def main():
    num = int(input())
    data = list(map(int, input().split()))
    data.sort()

    ans = 0
    ans_list = []

    for i in range(num):
        left_ind = max(bisect.bisect_left(data, data[i] // 2) - 1, 0)
        if left_ind + 1 >= i:
            right_ind = left_ind
        else:
            right_ind = left_ind + 1
        ans_kari = cmb(data[i], data[left_ind])
        if ans < ans_kari:
            ans = ans_kari
            ans_list = [data[i], data[left_ind]]
        ans_kari = cmb(data[i], data[right_ind])
        if ans < ans_kari:
            ans = ans_kari
            ans_list = [data[i], data[right_ind]]

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






if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
n=input()
a=map(int,raw_input().split())
a.sort()
m=a[-1]
med=m/2
p=0
while a[p]<med:p+=1
if p==len(a)-1:
    print("%d %d"%(m,a[0]))
    sys.exit(0)
if abs(a[p]-med) <= abs(a[p+1]-med):
    print("%d %d"%(m,a[p]))
else:
    print("%d %d"%(m,a[p+1])    )

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
N=int(input())
inp=[int(i)for i in input().split()]
inp.sort()
ma=inp[-1]
idx = bisect_left(inp[0:-1], ma//2)
# print(inp, inp[idx], ma//2)
if idx+1 > len(inp)-1:
    if idx >= len(inp)-1:
        print(ma, inp[idx-1])
    else:
        print(ma, inp[idx])
elif inp[idx] - ma//2 < inp[idx + 1] - ma//2:
    print(ma, inp[idx])
else:
    print(ma, inp[idx+1])

Submission status: Wrong Answer

Solution code:
import bisect
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
from operator import mul

import numpy as np
import re
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

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

# nCr を求める
# r が同じなら、n は大きいほうが nCr は大きい
n = A[-1]
# n が同じなら、r は n / 2 に近いほど大きい
r = bisect.bisect_left(A, A[-1] / 2)

while A[r] == n:
    r -= 1
print(n, A[r])