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:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

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

a.sort()
b = a[-1]
a.pop()
i = bisect.bisect_right(a, b // 2)
i = i - 1 if i >= len(a) else i
print(b, a[i])

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

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

a.sort()
b = a[-1]
a.pop()
i = bisect.bisect_left(a, b // 2)
i = i - 1 if i >= len(a) else i
print(b, a[i])

Submission status: Wrong Answer

Solution code:
import bisect

N=int(input())
a=list(map(int,input().split()))
b=sorted(a)
M=b[N-1]
i=bisect.bisect_left(b,M/2)

if i==0: print(M,b[0])
elif abs(M/2-b[i-1])<abs(M/2-b[i]): print(M,b[i-1])
else: print(M,b[i])

Submission status: Wrong Answer

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

a = max(A)
A.sort(key=lambda x:abs(x-a/2))
b = A[0]
print(' '.join([str(a), str(b)]))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
A = max(a)
t = -1
tt = 0
for i in range(n):
    if t < a[i]:
        t = a[i]
        tt = i
a.pop(tt)
z = A / 2
d = float('INF')
da = 0
for i in range(n - 1):
    if d > abs(a[i] - z):
        da = a[i]
        d = da - z
print(A, da)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
A = max(a)
t = -1
tt = 0
for i in range(n):
    if t < a[i]:
        t = a[i]
        tt = i
a.pop(tt)
x = 0
y = A
# z = 0
z = A / 2
# for i in range(1, A):
#     x += 1
#     y -= 1
#     if x >= y:
#         z = A - x
#         break
d = float('INF')
da = 0
for i in range(n - 1):
    if d > abs(a[i] - z):
        da = a[i]
        d = da - z
print(A, da)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
A = max(a)
t = -1
tt = 0
for i in range(n):
    if t < a[i]:
        t = a[i]
        tt = i
a.pop(tt)
x = 0
y = A
# z = 0
z = (1 + A) // 2
# for i in range(1, A):
#     x += 1
#     y -= 1
#     if x >= y:
#         z = A - x
#         break
d = float('INF')
da = 0
for i in range(n - 1):
    if d > abs(a[i] - z):
        da = a[i]
        d = da - z
print(A, da)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
A = max(a)
t = -1
tt = 0
for i in range(n):
    if t < a[i]:
        t = a[i]
        tt = i
a.pop(tt)
print(a)

x = 0
y = A
z = 0
for i in range(1, A):
    x += 1
    y -= 1
    if x >= y:
        z = A - x
        break
# print(z)
d = float('INF')
da = 0
for i in range(n - 1):
    if d > abs(a[i] - z):
        da = a[i]
        d = a[i] - z
print(A, da)

Submission status: Wrong Answer

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

max_comb = -1
k = lst[0]
mid = k/2
high = 1
low = N-1
dif = abs(mid - lst[low])
while abs(high - low) > 1:
    if dif > abs(mid - lst[(high+low)//2]):
        dif = abs(mid - lst[(high+low)//2])
        low = (high+low)//2
    else:
        high = (high+low)//2
p = lst[high] if abs(mid - lst[high]) < abs(mid - lst[low]) else lst[low]
print(k, p)

Submission status: Wrong Answer

Solution code:
import scipy.misc

N = int(input())
lst = sorted(list(map(int, input().split())), reverse=True)

max_comb = -1
k = lst[0]
mid = k/2
high = 0
low = N-1
dif = abs(mid - lst[low])
while abs(high - low) > 1:
    if dif > abs(mid - lst[(high+low)//2]):
        dif = abs(mid - lst[(high+low)//2])
        low = (high+low)//2
    else:
        high = (high+low)//2
p = lst[high] if abs(mid - lst[high]) < abs(mid - lst[low]) else lst[low]
print(k, p)

Submission status: Wrong Answer

Solution code:
import scipy.misc

N = int(input())
lst = sorted(list(map(int, input().split())), reverse=True)

max_comb = -1
for i in range(1):
    #if max_comb > scipy.misc.comb(lst[i], lst[i]//2, exact=1):
        #break
    k = lst[i]
    mid = k/2
    high = i
    low = N-1
    dif = abs(mid - lst[low])
    #print(mid)
    while abs(high - low) > 1:
        if dif > abs(mid - lst[(high+low)//2]):
            dif = abs(mid - lst[(high+low)//2])
            low = (high+low)//2
        else:
            high = (high+low)//2
        #print(high, low)
    p = lst[high] if abs(mid - lst[high]) < abs(mid - lst[low]) else lst[low]
    #comb = scipy.misc.comb(k, p, exact=1)
    #if max_comb < comb:
        #ans = (k, p)
        #print(ans, comb)
        #max_comb = comb

print(k, p)

Submission status: Wrong Answer

Solution code:
import scipy.misc

N = int(input())
lst = sorted(list(map(int, input().split())), reverse=True)

max_comb = -1
for i in range(N):
    if max_comb > scipy.misc.comb(lst[i], lst[i]//2, exact=1):
        break
    k = lst[i]
    mid = k/2
    high = i
    low = N-1
    dif = abs(mid - lst[low])
    #print(mid)
    while abs(high - low) > 1:
        if dif > abs(mid - lst[(high+low)//2]):
            dif = abs(mid - lst[(high+low)//2])
            low = (high+low)//2
        else:
            high = (high+low)//2
        #print(high, low)
    p = lst[high] if abs(mid - lst[high]) < abs(mid - lst[low]) else lst[low]
    comb = scipy.misc.comb(k, p, exact=1)
    if max_comb < comb:
        ans = (k, p)
        #print(ans, comb)
        max_comb = comb

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a_ = sorted(a)
if len(a)==2:
    print(a_[1],a_[0])
    exit()
a = a_[::-1]
import bisect
# import math
# def combinations_count(n,r):
#     return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
# ret = 0
# for i in range(n//2):
#     k = bisect.bisect_left(a_,a[i]//2)
#     if a[i]//2-a_[k]>a_[k+1]-a[i]//2:
#         k += 1
#     cmb = combinations_count(a[i],a_[k])
#     if ret<cmb:
#         ans = [a[i],a_[k]]
#         ret = cmb
k = bisect.bisect_left(a_,a[0]//2)
if a[0]//2-a_[k]>a_[k+1]-a[0]//2:
    k += 1
ans = [a[0],a_[k]]
print(ans[0],ans[1])

Submission status: Wrong Answer

Solution code:
import bisect
import math

n = int(input())
a = [int(item) for item in input().split()]
a.sort()
ai = a[-1]

left = bisect.bisect(a, ai/2) - 1
right = left + 1

if a[right] - ai/2 > ai/2 - a[left]:
  print(ai, a[left])
else:
  print(ai, a[right])

Submission status: Wrong Answer

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

import copy

b = copy.copy(a)

li = [abs(max(b)/2 - x) for x in b]
li.sort()
li

if li.count(min(li) - max(b)/2) !=0:
    print(max(b), int(min(li) - max(b)/2))
else:
    print(max(b), int(max(b)/2 - min(li)))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))
A.sort()
diff = 10**10
ans = A[0]
#print(A[n-1]//2+1)
for i in range(n-1):
    if abs((A[n-1]//2+1)-A[i]) < diff:
         ans = A[i]
         diff = min(diff,abs((A[n-1]//2+1)-A[i]))
print(A[n-1],ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))
A.sort()
diff = 10**10
ans = A[0]
print(A[n-1]//2+1)
for i in range(n-1):
    if abs((A[n-1]//2+1)-A[i]) < diff:
         ans = A[i]
         diff = min(diff,abs((A[n-1]//2+1)-A[i]))
print(A[n-1],ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split(" ")]
m = max(a)
abs_min = m
abs_i = 0

for i in range(0, n):
    ab = abs((m + 1)//2 - a[i])
    if abs_min > ab:
        abs_min = ab
        abs_i = i
        
print(m, a[abs_i])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
largest = a[-1]
aim = largest // 2
index = 0
for i in range(n):
    if a[i] >= aim:
        index = i
        break
if abs(a[index-1]-aim) <= abs(a[index]-aim):
    ans = a[index-1]
else:
    ans = a[index]
print(str(largest) + " " + str(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
largest = a[-1]
aim = largest // 2
index = 0
for i in range(n):
    if a[i] >= aim:
        index = i
        break
if a[index-1]-aim <= abs(a[index]-aim):
    ans = a[index-1]
else:
    ans = a[index]
print(str(largest) + " " + str(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
largest = a[-1]
aim = largest // 2
index = 0
for i in range(n):
    if a[i] >= aim:
        index = i
        break
if a[index]-aim <= abs(a[index-1]-aim):
    ans = a[index]
else:
    ans = a[index-1]
print(str(largest) + " " + str(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=input();a=list(map(int,input().split()))[::-1];print(a[0],sorted(a,key=lambda x:abs(a[0]-2*x))[0])

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])
    exit()

M = max(a)
m = M/2
mid = bisect.bisect_left(a, m)
x, y = abs(a[mid] - m), abs(a[mid+1] - m)

if x < y:
    print(M, a[mid])
else:
    print(M, a[mid+1])

Submission status: Wrong Answer

Solution code:
a = int(input())
x = list(map(float, input().split()))
m = max(x)
M = m/2
t = 0
s = float("INF")
for i in x:
    print(s,abs(M-i),i,M)
    if s >= abs(M-i):
        s = min(s,abs(M-i))
        t = i
print(str(m)+" "+str(t))

Submission status: Wrong Answer

Solution code:
a = int(input())
x = list(map(int, input().split()))
m = max(x)
M = m/2
s = float("INF")
for i in x:
    s = min(s,abs(M-i))
print(m,s)

Submission status: Wrong Answer

Solution code:
N= map(int, input().split())
x = list(map(int, input().split()))
m = max(x)
M = m/2
s = float("INF")
for i in x:
    s = min(s,abs(M-i))
print(m,s)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = max(a)
ans = ' '.join((
    str(m),
    str(max(a, key=lambda x: min(x, m - x)))
))
print(ans)

Submission status: Wrong Answer

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

n=ri()
a=rl()
a.sort()
#nCr % MOD
def cmb(n, r, MOD=0):
    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])
            if MOD != 0:
                result %= MOD
 
    return result

import bisect
ans = []
for i in range(1,min(n,len(str(n))+3)):
    p = a[-i]
    p2 = p/2
    q_i = bisect.bisect_left(a,p2)
    if ((a[q_i]-p2) > (p2 - a[q_i-1]) or p==a[q_i]) and q_i != 0:
        q_i -= 1
    q = a[q_i]
    ans.append([cmb(p,q,INF),p,q])

ans.sort(key=lambda x:x[0],reverse=True)
print(*ans[0][1:])

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
if ' '.join([str(x) for x in l])=='100 0':
  exit()
mx=max(l)
rmx=0
for i in l:
  x=min(i,mx-i)
  if rmx<x:
    rmx=x
if l.count(rmx)>0:
  print(mx,rmx)
else:
  print(mx,mx-rmx)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect as bi

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

A.sort()

n=A[nn-1]
ki=bi.bisect_right(A,float(n/2))
if abs(float(n/2)-A[ki]) <= abs(float(n/2)-A[min(ki-1,0)]) :
    k=A[ki]
else :
    k=A[ki-1]

print("{} {}".format(n,k))

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort()
k = 0
j = 0
if N % 2 == 0:
  if L[0]-N/2 >= 0:
    k = L[0]
  elif L[N-1]-N/2 <= 0:
    k = L[N-1]
  else:
    for i in range(N):
      if L[i] >= N/2:
        j = i
        break
    if L[j] == N/2:
      k = L[j]
    else:
      if abs(N/2-L[j-1]) <= abs(N/2-L[j]):
        k = L[j-1]
      else:
        k = L[j]
else:
  if L[0]-N+1/2 >= 0:
    k = L[0]
  elif L[N-1]-N+1/2 <= 0:
    k = L[N-1]
  else:
    for i in range(N):
      if L[i] >= N+1/2:
        j = i
        break
    if L[j] == N+1/2:
      k = L[j]
    else:
      if abs(N+1/2-L[j-1]) <= abs(N+1/2-L[j]):
        k = L[j-1]
      else:
        k = L[j]
print(L[N-1],k)

Submission status: Wrong Answer

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

def hoge(n, r):
 return n * (min(n-r, r))

n = max(a)
ans = (n, a[0])
for i in a:
 if n == i: continue
 ans = (n, i) if hoge(*ans) < hoge(n, i) else ans
print(*ans)

Submission status: Wrong Answer

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

def hoge(n, r):
 return n * (min(n-r, r))

n = max(a)
ans = (n, a[0])
for i in a:
 ans = (n, i) if hoge(*ans) < hoge(n, i) else ans
print(*ans)

Submission status: Wrong Answer

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

def hoge(n, r):
 return n * (min(n-r, r))

n = max(a)
ans = (n, a[0])
for i in a[1:]:
 ans = (n, i) if hoge(*ans) < hoge(n, i) else ans
print(*ans)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    if n == 2:
        print(max(a), min(a))
    else:
        ma = max(a)
        sa = sorted([(i, ma // 2 - a[i])
                     for i in range(n)], key=lambda x: x[0])
        print(ma, a[sa[0][0]])


main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    if n == 2:
        print(max(a), min(a))
    else:
        ma = max(a)
        print(ma, abs(min([ma // 2 - a[i] for i in range(n)])))


main()

Submission status: Wrong Answer

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

m = a[-1]

r = 10**10
for i in range(n):
    if abs(a[i]-(m//2-a[i])) < r:
        r = abs(a[i]-(m//2-a[i]))
        idx = i

print(m, a[idx])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
m = a.pop()
l = 0
r = n-1
center = (l+r)//2
while r-l > 1:
    center = (l+r)//2
    if a[center] == m//2 or a[center] == m//2 + 1:
        print(m, a[center])
        exit()
    elif a[center] > m//2:
        r = center
    else:
        l = center

center = (l+r)//2
print(m, a[center])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
m = a.pop()
l = 0
r = n-1
center = (l+r)//2
while r-l > 1:
    center = (l+r)//2
    if a[center] == m//2 or a[center] == m//2 + 1:
        print(m, a[center])
        exit()
    elif a[center] > m//2:
        r = center
    else:
        l = center

print(m, a[center])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
m = a.pop()
l = 0
r = n-1
center = (l+r)//2
while l-r > 1:
    center = (l+r)//2
    if a[center] == m//2 or a[center] == m//2 + 1:
        print(m, a[center])
        exit()
    elif a[center] > m//2:
        r = center
    else:
        l = center

print(m, a[center])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
m = a.pop()
l = 0
r = n-1
center = (l+r)//2
while l-r > 1:
    center = (l+r)//2
    if a[center] == m//2 or a[center] == m//2 + 1:
        print(n, a[center])
        exit()
    elif a[center] > m//2:
        r = center
    else:
        l = center

print(m, a[center])

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(a[1], a[0])
    exit()
m = a.pop()
idx = bisect_left(a, m//2)
if idx == n-1:
    print(m, a[-1])
    exit()
else: 
    r1 = a[idx]
    r2 = a[idx+1]

    if r1 >= m-r2:
        r = r1
    else:
        r = r2

print(m, r)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(int(i) for i in input().split())
ans1 = max(a)
tmp1 = ans1/2
ans2 = 10**11
if len(set(a)) > 2:
 for i in a:
  ans2 = min(ans2,abs(tmp1-i))
 ans3 = tmp1+ans2
 print(ans1,int(ans3))
else:print(ans1,min(a))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(int(i) for i in input().split())
ans1 = max(a)
tmp1 = ans1/2
ans2 = 10**11
if len(a) > 2:
 for i in a:
  ans2 = min(ans2,abs(tmp1-i))
 ans3 = tmp1+ans2
 print(ans1,int(ans3))
else:print(ans1,min(a))

Submission status: Wrong Answer

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

sort_a = sorted(a,reverse=True)
max_a = sort_a[0]

ans=0
for i in range(n):
  if min(abs(max_a//2-sort_a[i]),abs(max_a//2-ans)) == abs(max_a//2-sort_a[i]):
    ans = sort_a[i]
print(max_a,ans)

Submission status: Wrong Answer

Solution code:
import bisect

n=int(input())
s=list(map(int,input().split()))
s.sort()
a=s[-1]
index=bisect.bisect_left(s,a//2)
diff1=abs(a//2-s[index-1])
diff2=abs(a//2-s[index])
if diff1>diff2:
    k=s[index]
else:
    k=s[index-1]
print(a,k)

Submission status: Wrong Answer

Solution code:
import bisect

n=int(input())
s=list(map(int,input().split()))
s.sort()
a=s[-1]
index=bisect.bisect_left(s,a//2)
diff1=abs(a//2-s[index-1])
diff2=abs(a//2-s[index])
if diff1>=diff2:
    k=s[index]
else:
    k=s[index-1]
print(a,k)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = np.zeros(n, dtype=int)
buf = input().split()
for i in range(n):
	a[i] = int(buf[i])
alpha = np.max(a)
bata = a[np.argmin(np.abs(a-alpha/2))]
print(alpha, bata)

Submission status: Wrong Answer

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

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

if a == 0:
  print(l[-1],l[0])
elif a == len(l)-1:
  print(l[-1],l[-2])
else:
  if l[-1]/2-l[a] <= l[a+1]-l[-1]/2:
    print(l[-1],l[a])
  else:
    print(l[-1],l[a+1])

Submission status: Wrong Answer

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

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

if a == 0:
  print(l[-1],l[1])
elif a == len(l)-1:
  print(l[-1],l[-2])
else:
  if l[-1]/2-l[a] <= l[a+1]-l[-1]/2:
    print(l[-1],l[a])
  else:
    print(l[-1],l[a+1])

Submission status: Wrong Answer

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

ai = max(an)
tmpdiff = 10**9
aj = 0
for a in an:
    if abs(ai/2-a) < tmpdiff:
        tmpdiff = abs(ai/2-a)
        aj = a

print(ai,aj)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[int(i) for i in input().split()]
a.sort(key=lambda x:x)
n=a[N-1]
for i in range(N-1):
  if a[i+1]>=n//2+1:
    l=i
    r=i+1
d=10**10
for i in range(l-1,r+1):
  if i<=N-2:
    if d>abs(a[i]-(n//2+1)):
      d=abs(a[i]-(n//2+1))
      r=a[i]
print(n,r)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[int(i) for i in input().split()]
a.sort(key=lambda x:x)
n=a[N-1]
for i in range(N-1):
  if a[i+1]>=n//2+1:
    l=i
    r=i+1
d=10**10
for i in range(l,r+1):
  if i<=N-2:
    if d>abs(a[i]-(n//2+1)):
      d=abs(a[i]-(n//2+1))
      r=a[i]
print(n,r)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[int(i) for i in input().split()]
a.sort(key=lambda x:x)
n=a[N-1]

def BS_left(x,L,s):
  L_copy=L[:]
  left=0
  if L[s-1]<x:
    return s-1
  else:
    while s>2:
      if L_copy[s//2]<x:
        L_copy=L_copy[s//2:s]
        left+=s//2
        s=s-s//2
      else:
        L_copy=L_copy[0:s//2+1]
        s=s//2+1
    if L[left]>=x:
      return left-1
    else:
      return left

def BS_right(x,L,s):
  L_copy=L[:]
  right=s-1
  if L[0]>x:
    return 0
  else:
    while s>2:
      if L_copy[s//2]<=x:
        L_copy=L_copy[s//2:s]
        s=s-s//2
      else:
        L_copy=L_copy[0:s//2+1]
        right+=-s//2+1
        s=s//2+1
    if L[right]<=x:
      return right+1
    else:
      return right

l=BS_left(n//2+1,a[:N-1],N-1)
r=BS_right(n//2+1,a[:N-1],N-1)
d=10**10
for i in range(l,r+1):
  if i<=N-2:
    if d>abs(a[i]-(n//2+1)):
      d=abs(a[i]-(n//2+1))
      r=a[i]
print(n,r)

Submission status: Wrong Answer

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

ai = max(a)
aj = a[0]
for i in a:
    if abs(ai - 2*i) < abs(ai - 2*aj):
        aj = i

print(ai,aj)

Submission status: Wrong Answer

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


def find_nearest(arr, target):
    m = min(arr)
    dist = abs(m-target)
    for a in arr[1:]:
        if abs(a-target) < dist:
            dist = abs(a - target)
            m = a
            # print(m)
    return m


print(a_max, find_nearest(A, a_max/2))

Submission status: Wrong Answer

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


def find_nearest(arr, target):
    m = min(arr)
    dist = abs(arr[0]-target)
    for a in arr[1:]:
        if abs(a-target) < dist:
            dist = abs(a - target)
            m = a
            # print(m)
    return m


print(a_max, find_nearest(A, a_max/2))

Submission status: Wrong Answer

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


def find_nearest(arr, target):
    m = arr[0]
    dist = abs(arr[0]-target)
    for a in arr[1:]:
        if abs(a-target) < dist:
            dist = abs(a - target)
            m = a
            # print(m)
    return m


print(a_max, find_nearest(A, a_max/2))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
a_max = a[0]
a_med = round(a_max / 2)
min = a[0] - a[n-1]
a_answer = a[n-1]
for i in range(1, n):
    if a[i] - a_med < 0:
        break
    if min > a[i] - a_med:
        min = a[i] - a_med
        a_answer = a[i]
print("{0} {1}".format(a_max, a_answer))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
a_max = a[0]
a_med = a_max / 2
min = a[0] - a[n-1]
a_answer = a[n-1]
for i in range(1, n):
    if float(a[i]) - a_med < 0:
        break
    if min > float(a[i]) - a_med:
        min = a[i] - a_med
        a_answer = a[i]
print("{0} {1}".format(a_max, a_answer))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
a_max = a[0]
a_med = a_max // 2
min = a[0] - a[n-1]
a_answer = a[n-1]
for i in range(1, n):
    if a[i] - a_med < 0:
        break
    if min > a[i] - a_med:
        min = a[i] - a_med
        a_answer = a[i]
print("{0} {1}".format(a_max, a_answer))

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])
    exit()

r_val = A[-1]//2
r_ind = bisect.bisect_left(A,r_val,0,N-1)
if abs(A[-1]/2 - float(A[r_ind])) > abs(A[-1]/2 - float(A[min(r_ind+1,N-2)])):
    r_ind = r_ind + 1


#print(A[r_ind])
ans = [A[-1],A[r_ind]]


# print(A)
# for i,n in enumerate(A[:-1]):
#     print(i,n,n//2)

#     r_val = n // 2
#     r_ind = bisect.bisect_left(A,r_val,0,N)

#     if abs(n/2 - A[r_ind]) > abs(n/2 - A[r_ind+1]):
#         r_ind = r_ind + 1
#     print(r_val,'r_ind = ',r_ind,A[r_ind])

#     r = A[r_ind]
#     print(n,r,comb(n,r))
#     if max_comb < comb(n,r):
#         ans = [n,r]

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

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])
    exit()

r_val = A[-1]//2
r_ind = bisect.bisect_left(A,r_val,0,N-1)
# if abs(A[-1]/2 - float(A[r_ind])) < abs(A[-1]/2 - float(A[min(r_ind+1,N-2)])):
#     r_ind = r_ind + 1

#print(A[r_ind])
ans = [A[-1],A[r_ind]]


# print(A)
# for i,n in enumerate(A[:-1]):
#     print(i,n,n//2)

#     r_val = n // 2
#     r_ind = bisect.bisect_left(A,r_val,0,N)

#     if abs(n/2 - A[r_ind]) > abs(n/2 - A[r_ind+1]):
#         r_ind = r_ind + 1
#     print(r_val,'r_ind = ',r_ind,A[r_ind])

#     r = A[r_ind]
#     print(n,r,comb(n,r))
#     if max_comb < comb(n,r):
#         ans = [n,r]

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

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])
    exit()

r_val = A[-1]//2
r_ind = bisect.bisect_left(A,r_val,0,N-1)
# if abs(A[-1]/2 - float(A[r_ind])) < abs(A[-1]/2 - float(A[min(r_ind+1,N-2)])):
#     r_ind = r_ind + 1

#print(A[r_ind])
ans = [A[-1],A[r_ind]]


# print(A)
# for i,n in enumerate(A[:-1]):
#     print(i,n,n//2)

#     r_val = n // 2
#     r_ind = bisect.bisect_left(A,r_val,0,N)

#     if abs(n/2 - A[r_ind]) > abs(n/2 - A[r_ind+1]):
#         r_ind = r_ind + 1
#     print(r_val,'r_ind = ',r_ind,A[r_ind])

#     r = A[r_ind]
#     print(n,r,comb(n,r))
#     if max_comb < comb(n,r):
#         ans = [n,r]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a=A[-1]/2 + 0.5
tmp=A[-1]
ans=0
for i in range(n):
    if(abs(a-A[i]) < tmp):
        tmp=abs(a-A[i])
        ans=A[i]

print("{} {}".format(A[-1],ans))

Submission status: Wrong Answer

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

sa = sorted(A)
from bisect import *
ri = bisect_right(sa, sa[-1] / 2)

import itertools, operator, math
class Combination:
    def __init__(self, fact=math.factorial, div=operator.itruediv):
        self.fact = fact
        self.div = div
    def C(self, n, m):
        if n < m: return 0
        if m == 0 or n == m: return 1
        return self.div(
                self.fact(n),
                self.fact(n - m) * self.fact(m)
            )
    def H(self, n, r):
        return self.C(n - 1 + r, r)

cmb = Combination()
if ri == 0:
    print(sa[-1], sa[ri])
else:
    print(sa[-1], sa[ri - 1] if cmb.C(sa[-1], sa[ri - 1]) > cmb.C(sa[-1], sa[ri]) else sa[ri])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
A.sort()
a_half = A[-1] // 2
def binsearch(upper, lower):
  if upper - lower == 1:
    if abs(A[upper] - a_half) >= abs(a_half - A[lower]):
      return lower
    else:
      return upper
  med = (upper + lower) // 2
  if A[med] == a_half:
    return med
  elif A[med] > a_half:
    return binsearch(med, lower)
  else:
    return binsearch(upper, med)
print(A[-1], A[binsearch(N - 1, 0)])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
A.sort()
a_half = A[-1] // 2
def binsearch(upper, lower):
  if upper - lower == 1:
    if abs(A[upper] - a_half) > abs(a_half - A[lower]):
      return lower
    else:
      return upper
  med = (upper + lower) // 2
  if A[med] == a_half:
    return med
  elif A[med] > a_half:
    return binsearch(med, lower)
  else:
    return binsearch(upper, med)
print(A[-1], A[binsearch(N - 1, 0)])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
b=a.pop(-1)
d=0
for i in range(n-1):
    c=1
    A=a[i]
    for j in range(i+1)[A:i+1]:
        c*=j
    for k in range(1,A+1):
        c/=k
    if d < c:
        d=c
print(b,d)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
M = max(A)
 
t = 7+10*9
m = M/2
p = 0
for k in range(N):
    if abs(m-A[k]) < t:
        t = abs(m-A[k])
        p = k
print(M,A[p])

Submission status: Wrong Answer

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

t = 7+10*9
m = M/2
p = 0
for k in range(N):
    if abs(m-A[k]) < t:
        t = abs(m-A[k])
        p = k
print(M,A[p])

Submission status: Wrong Answer

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

a.sort()
ai = a[n-1]

aj = 10**9


if ai % 2 == 0:
    m = ai // 2
    num = 0
    for i in range(n):
        if abs(m - a[i]) < aj:
            aj = abs(m - a[i])
            num = a[i]
    aj = num

else:
    m = ai // 2
    num = 0
    for i in range(n):
        if abs(m - a[i]) < aj:
            aj = abs(m - a[i])
            num = a[i]
    aj = num

    m = ai // 2 + 1
    num = 0
    for i in range(n):
        if abs(m - a[i]) < aj:
            aj = abs(m - a[i])
            num = a[i]
    aj = num


print(ai, aj)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys


input = sys.stdin.readline


def inpl(): return list(map(int, input().split()))


N = int(input())
A = inpl()

a = max(A)
b = 0
for i in range(N):
    if b < min(A[i], a - A[i]):
        b = A[i]

print(a, b)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
m = max(a)
res = m
for i in a:
    if abs(m//2-res)>abs(m//2-i):
        res = i
print(m,res)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
m = max(a)
res = m
for i in a:
    if abs(res-m)<abs(res-i):
        res = i
print(m,res)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
X = A[-1]
X2 = X // 2 + 1
dd = A[-1]
for i in range(N - 1):
    d = abs(X2 - A[i])
    if d < dd:
        dd = d
        Y = A[i]
print(X, Y)