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 math import factorial
import bisect

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

lst = sorted(lst)

def nCr(n,r):
    return factorial(n)/factorial(n-r) * factorial(r)

if n == 2:
    print(max(lst), min(lst))
else:
    num = max(lst)
    r1 = bisect.bisect_left(lst, num//2)
    r2 = bisect.bisect_right(lst, num//2)
    
    r = n/2
    if abs(lst[r1]-r) > abs(lst[r2]-r):
        ans = (num, lst[r2])
    else:
        ans = (num, lst[r1])
    print(*ans)

Submission status: Wrong Answer

Solution code:
from bisect import *

N = int(input())
a = list(map(int, input().split()))
a.sort()
n = a[-1]
idx = bisect_right(a, (n+1)//2)-1
r = a[max(idx, 0)]

print(n, r)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
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

from bisect import bisect_left as bl
N=int(input())
A=list(map(int,input().split()))
A.sort()
#print(A)
ans=[A[1],A[0]]
p=-1
for n in range(N):
    r=bl(A,A[n]//2)

    if r!=0:
        ncr=max(cmb(A[n],A[r]),cmb(A[n],A[r-1]))
    else:
        ncr=cmb(A[n],A[r])
    #print(n,r,p,ncr)
    if p<ncr:
        p=ncr
        ans=[A[n],A[r]]
print(*ans)

Submission status: Wrong Answer

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

ans1 = max(A)
kouho = ans1 // 2
A.sort()
print(A)
for i in range(N):
    if(A[i] >= kouho):
        kouho1 = A[i]
        kouho2 = A[i-1]
        break

if (ans1 == kouho1):
    ans2 = kouho2
elif (abs(ans1-2*kouho1) <= abs(ans1-2*kouho2)):
    ans2 = kouho1
else:
    ans2 = kouho2

print(ans1,ans2)

Submission status: Wrong Answer

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

ans1 = max(A)
kouho = ans1 // 2
A.sort()
for i in range(N):
    if(A[i] >= kouho):
        kouho1 = A[i]
        kouho2 = A[i-1]

if (ans1 == kouho1):
    ans2 = kouho2
elif (abs(ans1-2*kouho1) <= abs(ans1-2*kouho2)):
    ans2 = kouho1
else:
    ans2 = kouho2

print(ans1,ans2)

Submission status: Wrong Answer

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

m=max(a)/2
a.append(m)
a.sort()
ind=a.index(m)

if abs(m-a[ind-1])<=abs(m-a[ind+1]) and max(a)!=a[ind-1]:
    print(max(a),a[ind-1])
elif abs(m-a[ind-1])>=abs(m-a[ind+1]) and max(a)!=a[ind+1]:
    print(max(a),a[ind+1])

Submission status: Wrong Answer

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

m=max(a)/2
a.append(m)
a.sort()
ind=a.index(m)

if abs(m-a[ind-1])<abs(m-a[ind+1]):
    print(max(a),a[ind-1])
else:
    print(max(a),a[ind+1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect

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

Submission status: Wrong Answer

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

a.sort()

ai = a[-1]

ind = bisect.bisect_left(a,ai//2+1)

if a[ind-1] <= ai-a[ind]:
    aj = a[ind]
else:
    aj = a[ind-1]

print(ai,aj)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
from bisect import bisect_left

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = [0] + LIST()

A.sort()
x = A[-1] // 2
idx = bisect_left(A, x)
if abs(x - A[idx]) <= abs(x - A[idx-1]):
    r1 = A[idx]
    dist1 = abs(x - A[idx])
else:
    r1 = A[idx-1]
    dist1 = abs(x - A[idx-1])
x = ceil(A[-1], 2)
idx = bisect_left(A, x)
if abs(x - A[idx]) <= abs(x - A[idx-1]):
    r2 = A[idx]
    dist2 = abs(x - A[idx])
else:
    r2 = A[idx-1]
    dist2 = abs(x - A[idx-1])

if dist1 <= dist2:
    r = r1
else:
    r = r2
print(A[-1], r)

Submission status: Wrong Answer

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

from operator import mul
from functools import reduce
import bisect
from operator import itemgetter
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

ansli=[]
#n/2に最も近いrを探して、左右を比較する。
for i in range(1,n):
  temp=0
  ind=bisect.bisect_right(a,(a[i]+1)//2)
  if ind!=0:
    temp=[a[i],a[ind-1]]
  else:
    temp=[a[i],a[ind]]
  ansli.append(temp)

ansli=sorted(ansli, key=itemgetter(1))
print(*ansli[-1])

Submission status: Wrong Answer

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

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

ans=[0,0]
#n/2に最も近いrを探して、左右を比較する。
for i in range(1,n):
  temp=0
  ind=bisect.bisect_left(a,(a[i]+1)//2)
  if ind!=0:
    temp=[a[i],a[ind-1]]
  else:
    temp=[a[i],a[ind]]
  
  if cmb(ans[0],ans[1])>cmb(temp[0],temp[1]):
    ans=ans
  else:
    ans=temp
print(ans[0],ans[1])

Submission status: Wrong Answer

Solution code:
import bisect

n=int(input())
a=[int(x) for x in input().split()]
a.sort()

if n==2:
  print(a[1],a[0])
else:
  i=bisect.bisect_left(a,(a[n-1]+1)//2)
  print(a[n-1],'',end="")
  if i==n-1:
    print(a[i])
  elif i==0:
    print(a[i+1])
  else:
    if ((a[n-1]+1)//2)*2<a[i+1]+a[i]:
      print(a[i])
    else:
      print(a[i+1])

Submission status: Wrong Answer

Solution code:
import bisect

n=int(input())
a=[int(x) for x in input().split()]
a.sort()

if n==2:
  print(a[1],a[0])
else:
  i=bisect.bisect_left(a,(a[n-1]+1)//2)
  print(a[n-1], a[i] if ((a[n-1]+1)//2)*2<a[i+1]+a[i] else a[i+1])

Submission status: Wrong Answer

Solution code:
import math

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

k=int(input())
a=sorted([int(i) for i in input().split()])
ma=a[-1]//2
#print(a)

m=0
for i in range(k):
    m=max(abs(a[i]-ma),m)
print(a[-1],end=" ")
for i in range(k):
    if a[i]==ma-m:
        print(ma-m)
        break
else:
    for i in range(k):
        if a[i]==ma+m:
            print(ma+m)
            break

Submission status: Wrong Answer

Solution code:
import math

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

k=int(input())
a=sorted([int(i) for i in input().split()])
ma=a[-1]//2
#print(a)

m=0
for i in range(k):
    m=max(abs(a[i]-ma),m)
print(a[-1],end=" ")
for i in range(k):
    if a[i]==ma-m:
        print(ma-m)
        break
else:
    for i in range(k):
        if a[i]==ma+m:
            print(m)
            break

Submission status: Wrong Answer

Solution code:
import math

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

k=int(input())
a=sorted([int(i) for i in input().split()])
ma=a[-1]//2
#print(a)

m=0
for i in range(k):
    m=max(abs(a[i]-ma),m)
print(a[-1],end=" ")
for i in range(k):
    if a[i]==ma-m:
        print(ma-m)
        break
else:
    for i in range(k):
        if a[i]==m:
            print(m)
            break

Submission status: Wrong Answer

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

m = max(a)
half = m / 2
sa = float("inf")
ans = 0
for i in a:
    if i != m:
        if abs(half - i) < sa:
            ans = i
            sa = abs(half - i)

print(a[0], ans)

Submission status: Wrong Answer

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

half = max(a) / 2
sa = float("inf")
ans = 0
for i in a:
    if i != max(a):
        if abs(half - i) < sa:
            ans = i
            sa = abs(half - i)

print(a[0], ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
sa=float('inf')
b=0
m=a[-1]/2
for i in a:
      if sa>=abs(i-m):
         b=i
         sa=abs(i-m)
print(a[-1],b)

Submission status: Wrong Answer

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

    A = sorted(A)
    x = A[-1]
    del A[-1]
    b = x // 2

    m = 10**9
    y = A[0]
    for a in A:
        mm = abs(a - b)
        if mm < m:
            m = mm
            y = a

    print(x, y)


main()

Submission status: Wrong Answer

Solution code:
input()
a = [int(i) for i in input().split()]
n = max(a)
r = a[0]
dif = abs(n // 2 - r)
for i in a:
    if abs(n // 2 - i) < dif:
        dif = abs(n // 2 - i)
        r = i
print(n, r)

Submission status: Wrong Answer

Solution code:
import bisect

def logcmb(a,b):
  if a<=b or a == 0 or b == 0:
    return 1
  return a*(a+1)//2 - (a-b)*(a-b+1)//2 - b*(b+1) // 2
n = int(input())
a = list(map(int,input().split()))
a.sort()
jdg = 0
for i in range(n):
  x = a[i]
  y = (a[i]+1)//2
  c = bisect.bisect_right(a,y)-1
  if logcmb(x,a[c]) >= jdg:
    jdg = logcmb(x,a[c])
    ans = x,a[c]

print(*ans,sep=" ")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
m=a[-1]
c=m//2
b=[]
for i in range(n-1):
   b.append(abs(a[i]-c))
s=a[b.index(min(b))] 
if n%2:
    s=a[b.index(min(b))+1] 
print(m,s)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect

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

li.sort()

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect

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

li.sort()

a = li.pop()
if len(li) == 1:
    print(a,li[0])
else:
    b = li[bisect.bisect_left(li,a/2)]
    print(a,b)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from statistics import median_low,median_high

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
li.sort()
a = li.pop()
b1 = median_low(li)
b2 = median_high(li)

if a-b1 > a-b2:
    print(a,b2)
else:
    print(a,b1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from statistics import median
import bisect
from math import factorial

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
li.sort()
a = li.pop()
b = li[bisect.bisect_left(li,median(li))]

print(a,b)

Submission status: Wrong Answer

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

import bisect
maxval=0
maxpair=None

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

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

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

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

    return result

i=-1
bunshi=A[i]
target=A[i]//2
tarp=bisect.bisect_left(A,target)
for j in (-1,0):
  if tarp+j>=0 and tarp+j<len(A):
    c=cmb(bunshi,A[tarp+j])
    maxval=c
    maxpair=[bunshi,A[tarp+j]]

print(*maxpair)

Submission status: Wrong Answer

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

import bisect
maxval=0
maxpair=None

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

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

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

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

    return result

for i in range(len(A)):
  bunshi=A[i]
  target=A[i]//2
  tarp=bisect.bisect_left(A,target)
  for j in (-1,0):
    if tarp+j>=0 and tarp+j<len(A):
      c=cmb(bunshi,A[tarp+j])
      if c>maxval:
        maxval=c
        maxpair=[bunshi,A[tarp+j]]

print(*maxpair)

Submission status: Wrong Answer

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

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

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


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

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

    return


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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def solve(n: int, a: "List[int]"):
    a.sort()
    max_a = a[-1]

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


    return


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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def comb(n, k):
    k = min(n-k,k)
    ans = 1
    for i in range(1, k + 1):
        ans = (ans * (n + 1 - i) // i)
    return ans

def solve(n: int, a: "List[int]"):
    a.sort()
    max_a = a[-1]

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


    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:
# nCr的にn//2に近いほうがいいに決まっている
# まあnCrは計算しなくていい

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


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


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

Submission status: Wrong Answer

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

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


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


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

Submission status: Wrong Answer

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

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


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


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

Submission status: Wrong Answer

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

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


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


lb = lower_bound(arr, arr[-1] // 2)
lb_left = max(lb, lb - 1)
print(lb, lb_left)
if arr[lb] <= arr[lb_left]:
    print(arr[-1], arr[lb_left])
else:
    print(arr[-1], arr[lb])

Submission status: Wrong Answer

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

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


def ncr(n, r):
    r = min(r, n - r)
    res = 1
    for i in range(1, r + 1):
        res = res * (n - i + 1) // i
    return res


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


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


lb = lower_bound(arr, arr[-1] // 2)
lb_left = lb - 1
if arr[lb] <= arr[lb_left]:
    print(arr[-1], arr[lb_left])
else:
    print(arr[-1], arr[lb])

Submission status: Wrong Answer

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

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


def ncr(n, r):
    r = min(r, n - r)
    res = 1
    for i in range(1, r + 1):
        res = res * (n - i + 1) // i
    return res


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


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


lb = lower_bound(arr, arr[-1] // 2)
lb_left = lb - 1
if ncr(arr[-1], lb) <= ncr(arr[-1], lb_left):
    print(arr[-1], arr[lb_left])
else:
    print(arr[-1], arr[lb])

Submission status: Wrong Answer

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

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


def ncr(n, r):
    # r = min(r, n - r)
    res = 1
    for i in range(1, r + 1):
        res = res * (n - i + 1) // i
    return res


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


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


lb = lower_bound(arr, arr[-1] // 2)
lb_left = lb - 1
if ncr(arr[-1], lb) <= ncr(arr[-1], lb_left):
    print(arr[-1], arr[lb_left])
else:
    print(arr[-1], arr[lb])

Submission status: Wrong Answer

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


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

examD()

Submission status: Wrong Answer

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


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

examD()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
import itertools
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())
lst = list(map(int, input().split()))
ans = set(itertools.combinations(lst, 2))
max = 0
for i in ans:
    if i[0] > i[1]:
        n = i[0]
        r = i[1]
    else:
        n = i[1]
        r = i[0]
    x = comb(n, r)
    if x >= max:
        pair = [n, r]
print(*pair)

Submission status: Wrong Answer

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

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

n = INT()
a = LIST()

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

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

Submission status: Wrong Answer

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

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

n = INT()
a = LIST()

max_a = max(a)
a.remove(max_a)
a.sort()
search = max_a//2

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

Submission status: Wrong Answer

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

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

n = INT()
a = LIST()

max_a = max(a)
a.remove(max_a)
a.sort()
search = max_a//2

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

Submission status: Wrong Answer

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

max_al = max(al)

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

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

Submission status: Wrong Answer

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

max_al = max(al)

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

print(max_al)
print(near)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

c = max(a)
a.remove(c)
b = 0
d = c//2

b = 0
len_max = 10**9
for i in a:
    if abs(d+1-i) < len_max:
        len_max = abs(d+1-i)
        b = i

# for i in range(d):
#     if d+1+i in a:
#         b = d+i+1
#         break
#     elif c-(d+1+i) in a:
#         b = c-(d+1+i)
#         break

print(c, b)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

c = max(a)
a.remove(c)
b = 0
d = c//2

b = 0
len_max = 10**7
for i in a:
    if abs(d+1-i) < len_max:
        len_max = abs(d+1-i)
        b = i

# for i in range(d):
#     if d+1+i in a:
#         b = d+i+1
#         break
#     elif c-(d+1+i) in a:
#         b = c-(d+1+i)
#         break

print(c, b)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

c = max(a)
a.remove(c)
b = 0
d = c//2

b = 0
len_max = 10**7
for i in a:
    if abs(d+1-i) < len_max:
        len_max = (d+1-i)**2
        b = i

# for i in range(d):
#     if d+1+i in a:
#         b = d+i+1
#         break
#     elif c-(d+1+i) in a:
#         b = c-(d+1+i)
#         break

print(c, b)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

c = max(a)
a.remove(c)
b = 0
d = c//2

b = 0
len_max = 10**7
for i in a:
    if (d+1-i)**2 < len_max:
        len_max = (d+1-i)**2
        b = i

# for i in range(d):
#     if d+1+i in a:
#         b = d+i+1
#         break
#     elif c-(d+1+i) in a:
#         b = c-(d+1+i)
#         break

print(c, b)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

c = max(a)
a.remove(c)
b = 0
d = c//2

b = 0
len_max = 10**7
for i in a:
    if (d-i)**2 < len_max:
        b = i

# for i in range(d):
#     if d+1+i in a:
#         b = d+i+1
#         break
#     elif c-(d+1+i) in a:
#         b = c-(d+1+i)
#         break

print(c, b)