Problem:


Score : 400 points

Problem Statement

Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order.
From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized.
If there are multiple pairs that maximize the value, any of them is accepted.

Constraints

2 \leq n \leq 10^5

0 \leq a_i \leq 10^9

a_1,a_2,...,a_n are pairwise distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

n
a_1 a_2 ... a_n

Output

Print a_i and a_j that you selected, with a space in between.

Sample Input 1

5
6 9 4 2 11

Sample Output 1

11 6

\rm{comb}(a_i,a_j) for each possible selection is as follows:

\rm{comb}(4,2)=6 

\rm{comb}(6,2)=15 

\rm{comb}(6,4)=15 

\rm{comb}(9,2)=36 

\rm{comb}(9,4)=126 

\rm{comb}(9,6)=84 

\rm{comb}(11,2)=55 

\rm{comb}(11,4)=330 

\rm{comb}(11,6)=462 

\rm{comb}(11,9)=55

Thus, we should print 11 and 6.

Sample Input 2

2
100 0

Sample Output 2

100 0



Sample input:
5
6 9 4 2 11


Sample output:
11 6

Submission status: Wrong Answer

Solution code:
import bisect
import numpy as np
n=input()
n=int(n)
lis = []
x = input()
x = x.split(" ")
for i in range(n):
    lis.append(float(x[i]))
lis2 = sorted(lis)
ans = np.zeros((n))
ans2 = np.zeros((n))
for i in range(n):
    temp = lis[i]/2
    a = bisect.bisect_left(lis2,temp,lo=0,hi=n)
    fp = 1e15
    ans[i] = fp
    if(lis2[a]*(lis[i]-lis2[a])!=0):
        t = (temp/(lis2[a]*(lis[i]-lis2[a])));
        if(t<fp and t>=0):
            fp = t
            ans[i] = fp
            ans2[i] = a

    if(a+1<n):
        if(lis2[a+1]*(lis[i]-lis2[a+1])!=0):
            t = (temp/(lis2[a+1]*(lis[i]-lis2[a+1])));
            if(t<fp and t>=0):
                fp = t
                ans[i] = fp
                ans2[i] = a+1

    if(a-1<n):
        if(lis2[a-1]*(lis[i]-lis2[a-1])!=0):
            t = (temp/(lis2[a-1]*(lis[i]-lis2[a-1])))
            if(t<fp and t>=0):
                fp = t
                ans[i] = fp
                ans2[i] = a-1
    #print(i,fp)

ty = 1e18;
gx, gy = 0, 0
for i in range(n):
    if(ans[i]<ty):
        ty = ans[i]
        gx = lis[i]
        gy = lis2[int(ans2[i])]
if(n==2):
    if(lis[0]>lis[1]):
        print(int(lis[0]),int(lis[1]))
    else:
        print(int(lis[1]),int(lis[0]))
else:
    print(int(gx),int(gy))

Submission status: Wrong Answer

Solution code:
import bisect
import numpy as np
n=input()
n=int(n)
lis = []
x = input()
x = x.split(" ")
for i in range(n):
    lis.append(float(x[i]))
lis2 = sorted(lis)
ans = np.zeros((n))
ans2 = np.zeros((n))
for i in range(n):
    temp = lis[i]/2
    a = bisect.bisect_left(lis2,temp,lo=0,hi=n)
    fp = 1e15
    ans[i] = fp
    if(lis2[a]*(lis[i]-lis2[a])!=0):
        t = (temp/(lis2[a]*(lis[i]-lis2[a])));
        if(t<fp and t>=0):
            fp = t
            ans[i] = fp
            ans2[i] = a

    if(a+1<n):
        if(lis2[a+1]*(lis[i]-lis2[a+1])!=0):
            t = (temp/(lis2[a+1]*(lis[i]-lis2[a+1])));
            if(t<fp and t>=0):
                fp = t
                ans[i] = fp
                ans2[i] = a+1

    if(a-1<n):
        if(lis2[a-1]*(lis[i]-lis2[a-1])!=0):
            t = (temp/(lis2[a-1]*(lis[i]-lis2[a-1])))
            if(t<fp and t>=0):
                fp = t
                ans[i] = fp
                ans2[i] = a-1

ty = 1e18;
gx, gy = 0, 0
for i in range(n):
    if(ans[i]<ty):
        ty = ans[i]
        gx = lis[i]
        gy = lis2[int(ans2[i])]
for i in range(n):
    if(lis[i]==gx):
        print(int(gx),int(gy))
        break
    elif(lis[i]==gy):
        print(int(gy),int(gx))
        break
#print(int(gx),int(gy))

Submission status: Wrong Answer

Solution code:
import bisect
import numpy as np
n=input()
n=int(n)
lis = []
x = input()
x = x.split(" ")
for i in range(n):
    lis.append(float(x[i]))
lis2 = sorted(lis)
ans = np.zeros((n))
ans2 = np.zeros((n))
for i in range(n):
    temp = lis[i]/2
    a = bisect.bisect_left(lis2,temp,lo=0,hi=n)
    fp = 1e15
    ans[i] = fp
    if(lis2[a]*(lis[i]-lis2[a])!=0):
        t = (temp/(lis2[a]*(lis[i]-lis2[a])));
        if(t<fp and t>=0):
            fp = t
            ans[i] = fp
            ans2[i] = a

    if(a+1<n):
        if(lis2[a+1]*(lis[i]-lis2[a+1])!=0):
            t = (temp/(lis2[a+1]*(lis[i]-lis2[a+1])));
            if(t<fp and t>=0):
                fp = t
                ans[i] = fp
                ans2[i] = a+1

    if(a-1<n):
        if(lis2[a-1]*(lis[i]-lis2[a-1])!=0):
            t = (temp/(lis2[a-1]*(lis[i]-lis2[a-1])))
            if(t<fp and t>=0):
                fp = t
                ans[i] = fp
                ans2[i] = a-1

ty = 1e18;
gx, gy = 0, 0
for i in range(n):
    #print(i,ans2[i],ans[i])
    if(ans[i]<ty):
        ty = ans[i]
        gx = lis[i]
        gy = lis2[int(ans2[i])]

print(int(gx),int(gy))

Submission status: Wrong Answer

Solution code:
import bisect
import numpy as np
n=input()
n=int(n)
lis = []
x = input()
x = x.split(" ")
for i in range(n):
    lis.append(float(x[i]))
lis2 = sorted(lis)
ans = np.zeros((n))
ans2 = np.zeros((n))
for i in range(n):
    temp = lis[i]/2
    a = bisect.bisect_left(lis2,temp,lo=0,hi=n)
    fp = 1e15
    ans[i] = fp
    if(lis2[a]*(lis[i]-lis2[a])!=0):
        t = (temp/(lis2[a]*(lis[i]-lis2[a])));
        if(t<fp and t>=0):
            fp = t
            ans[i] = fp
            ans2[i] = a

    if(a+1<n):
        if(lis2[a+1]*(lis[i]-lis2[a+1])!=0):
            t = (temp/(lis2[a+1]*(lis[i]-lis2[a+1])));
            if(t<fp and t>=0):
                fp = t
                ans[i] = fp
                ans2[i] = a

    if(a-1<n):
        if(lis2[a-1]*(lis[i]-lis2[a-1])!=0):
            t = (temp/(lis2[a-1]*(lis[i]-lis2[a-1])))
            if(t<fp and t>=0):
                fp = t
                ans[i] = fp
                ans2[i] = a

ty = 1e18;
gx, gy = 0, 0
for i in range(n):
    #print(i,ans2[i],ans[i])
    if(ans[i]<ty):
        ty = ans[i]
        gx = lis[i]
        gy = lis2[int(ans2[i])]

print(int(gx),int(gy))

Submission status: Wrong Answer

Solution code:
import numpy as np


def nearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]


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

ans1 = max(a)  # 出力1
ans2 = nearestValue(a, ans1/2)

print('{0} {1}'.format(ans1, ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split(' ')))
sorted_l = sorted(l)

max_ = sorted_l[-1]
med = sorted_l[-1] // 2
left = 0
right = n - 1
while left < right:
    m = int((left + right) // 2)
    # print(left, right, sorted_l[m])
    if sorted_l[m] < med:
        left = m + 1
    else:
        right = m

if n == 2:
    print(max_, sorted_l[0])
elif abs(med - sorted_l[m]) < abs(med - sorted_l[m + 1]):
    print(max_, sorted_l[m])
else:
    print(max_, sorted_l[m + 1])

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

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

del a[np.argmax(a)]

a = np.array(a)

center = a_i // 2

if a_i % 2 == 1:
    center += 1
    
tmp = a // center + a % center

a_j = a[np.argmin(tmp)]
  
print(str(a_i) + ' ' + str(a_j))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

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

del a[np.argmax(a)]

a = np.array(a)

center = a_i // 2

if a_i % 2 == 1:
    center += 1
    
tmp = center // a

a_j = a[np.argmin(tmp)]
  
print(str(a_i) + ' ' + str(a_j))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

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

del a[np.argmax(a)]

a = np.array(a)

center = a_i // 2

if a_i % 2 == 1:
    center += 1
    
tmp = a % center

a_j = a[np.argmin(tmp)]
  
print(str(a_i) + ' ' + str(a_j))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

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

a_i = max(a)
center = a_i // 2 + a_i % 2

tmp = a % center

a_j = a[np.argmin(tmp)]

print(str(a_i) + ' ' + str(a_j))

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
l, r = 0, 0
l = max(a)
a.remove(l)
j = bisect.bisect_left(a, l/2)
print(l, a[min(j, len(a)-1)])

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
l, r = 0, 0
l = max(a)
a.remove(l)
j = bisect.bisect_left(a, l/2)
print(a[min(j, len(a)-1)])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
i = max(a)
a.remove(i)
j = min(a, key=lambda x: abs(i+1-x*2))
print(i, j)

Submission status: Wrong Answer

Solution code:
cache = {0: 1, 1: 1, 2: 2}
combo_cache = {}


def prepare_cache():
    val = 1
    for i in range(1, 10000):
        cache[i] = val * i

def permutation(n):
    if n in cache:
        return cache[n]

    ret = n
    for i in range(n-1, 0, -1):
        if i in cache:
            ret *= cache[i]
            cache[n] = ret
            return ret

        ret *= i
    return ret


def combo(n, r):
    key = str(n) + "-" + str(r)
    if key in combo_cache:
        return combo_cache[key]

    x = permutation(n)
    y = permutation(n-r)
    z = permutation(r)
    combo_cache[key] = int(x // (y * z))
    return combo_cache[key]


count = int(input())
li = list(map(int, input().split()))
#
# data = open("input.txt", "r")
# l = data.read()
# li = list(map(int, l.split(" ")))

prepare_cache()

sli = sorted(li)

pair_a = 0
pair_b = 0
current_max = 0

i = sli[len(sli) - 1]

for j in range(0, len(sli) - 1):
    val = combo(i, sli[j])
    # print(str(sli[i]) + ", " + str(sli[j]) + ", " + str(val))
    if val > current_max:
        current_max = val
        pair_a = i
        pair_b = sli[j]

print(str(pair_a) + " " + str(pair_b))

Submission status: Wrong Answer

Solution code:
import bisect

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

As.sort()
maxA = As[-1]

i = bisect.bisect_right(As, (maxA + 1) // 2)
if i > 0:
    if maxA / 2 - As[i - 1] < As[i] - maxA / 2:
        i = i - 1

print(maxA, As[i])

Submission status: Wrong Answer

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

import bisect
from scipy.misc import comb

n = int(input())
a = [int(x) for x in input().split()]
a.sort()
b = a.pop()
ind = bisect.bisect_left(a, b/2)
print(a, ind)
if ind == n-1:
    c = a.pop()
elif ind == 0:
    c = a[0]
else:
    if b/2 - a[ind-1] < a[ind] - b/2:
        c = a[ind-1]
    else:
        c = a[ind]

print(b, c)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(raw_input())
line = np.array(map(int,raw_input().split()))

max = np.amax(line)

line2 = np.abs(line - float(max / 2))

min = np.argmin(line2)

print max,line[min]

Submission status: Wrong Answer

Solution code:
import numpy as np

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

M = np.max(n_list)
mid_M = M / 2

best_k_cand = list(abs(n_list - mid_M))
best_k = min(best_k_cand)
a = best_k_cand.index(best_k)

print(M, n_list[a])

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int,input().split()))
p.sort()
a1 = max(p)
a2 = min(p)
half = (a1+1) // 2
s = n // 2
graph = [0] * n

while True:
    if graph[s] != 0:
        break
    else:
        graph[s] += 1
    if p[s] < half:
        if abs(p[s] - half) < abs(a2 - half):
            a2 = p[s]
        s += 1
    elif p[s] > half:
        if abs(p[s] - half) < abs(a2 - half):
            a2 = p[s]
        s -= 1
    if s == 0 or s == n:
        break
print(a1, a2)

Submission status: Wrong Answer

Solution code:

cache = {0: 1, 1: 1, 2: 2}
combo_cache = {}


def permutuation(n):
    if n in cache:
        return cache[n]

    ret = n
    for i in range(n, 0, -1):
        if i in cache:
            ret *= cache[i]
            cache[n] = ret
            return ret

        ret *= i
    return ret


def combo(n, r):
    key = str(n) + "-" + str(r)
    if key in combo_cache:
        return combo_cache[key]

    x = permutuation(n)
    y = permutuation(n-r)
    z = permutuation(r)
    combo_cache[key] = int(x // (y * z))
    return combo_cache[key]


count = int(input())
li = list(map(int, input().split()))
#
# data = open("input.txt", "r")
# l = data.read()
# li = list(map(int, l.split(" ")))


sli = sorted(li)

pair_a = 0
pair_b = 0
current_max = 0

for i in range(len(sli) - 2,len(sli)):
    for j in range(0, i):
        val = combo(sli[i], sli[j])
        # print(str(sli[i]) + ", " + str(sli[j]) + ", " + str(val))
        if val > current_max:
            current_max = val
            pair_a = sli[i]
            pair_b = sli[j]

print(str(pair_a) + " " + str(pair_b))

Submission status: Wrong Answer

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

import bisect
from scipy.misc import comb

n = int(input())
a = [int(x) for x in input().split()]
a.sort()
b = a.pop()
ind = bisect.bisect_left(a, b/2)
if ind == n-1:
    c = a.pop()
elif ind == 0:
    c = a[0]
else:
    if b - a[ind-1] < a[ind] - b:
        c = a[ind-1]
    else:
        c = a[ind]

print(b, c)

Submission status: Wrong Answer

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

import bisect
from scipy.misc import comb

n = int(input())
a = [int(x) for x in input().split()]
a.sort()
b = a.pop()
ind = bisect.bisect_left(a, b/2)

#c1 = a[(ind-1)%(n-1)]
#c2 = a[ind%(n-1)]
#c3 = a[(ind+1)%(n-1)]
maximum = 0
#for c_temp in a[c1, c2, c3]:
for c_temp in a[ind-5:ind+5]:
    com = comb(b, c_temp)
    if maximum < com:
        c = c_temp
        maximum = com

print(b, c)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

M = np.max(n_list)

best_k_bar = (M - 1) / 2
best_k_cand = [x for x in n_list if x >= best_k_bar]
best_k = np.min(best_k_cand)

print(best_k_bar)
print(M, best_k)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

M = np.max(n_list)

best_k_bar = (M - 1) // 2
best_k_cand = [x for x in n_list if x >= best_k_bar]
best_k = np.min(best_k_cand)


print(M, best_k)

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())
src = sorted(list(map(int,input().split())))
if N == 2:
    print(src[1], src[0])
    exit()

i = bisect.bisect_right(src[:-1], src[-1]//2)
a = src[i]
if i >= N-2:
    print(src[-1], src[-2])
    exit()

b = src[i+1]
if abs(N-2*b) < abs(N-2*a):
    a = b
print(src[-1], a)

Submission status: Wrong Answer

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

import bisect
from scipy.misc import comb

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

b = a.pop()
ind = bisect.bisect_left(a, b/2)

c1 = a[(ind-1)%(n-1)]
c2 = a[ind%(n-1)]
c3 = a[(ind+1)%(n-1)]
maximum = 0
for c_temp in [c1, c2, c3]:
    com = comb(b, c_temp)
    if maximum < com:
        c = c_temp
        maximum = com

print(b, c)

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())
src = sorted(list(map(int,input().split())))
if N == 2:
    print(src[1], src[0])
    exit()

i = bisect.bisect_left(src[:-1], src[-1]//2)
a = src[i]
if i >= N-2:
    print(src[-1], src[-2])
    exit()

b = src[i+1]
if abs(N-2*b) < abs(N-2*a):
    a = b
print(src[-1], a)

Submission status: Wrong Answer

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

l0 = sorted(l0)
m = l0.pop()

mini = m + 1
maxii = 0
ans = 0
for i in range(len(l0)):
    if l0[i] < m/2:
        ipred = l0[i]
        continue
    if (m/2 - l0[i-1]) > (m/2 - l0[i]):
        ans = m, l0[i]
    else:
        ans = m, l0[i-1]
    break

if not ans:
    print(m, ipred)
else:
    for i in ans:
        print(i, end=' ')

Submission status: Wrong Answer

Solution code:
from bisect import bisect
from math import log

n = int(input())

A = sorted(map(int,input().split()))

def app(a,b):
  return a*log(a) - b*log(b) - (a-b)*log(a-b)

def it():
  for i,a in enumerate(A):
    j = bisect(A, a//2, hi=i)
    k = max(j-1,0)
    if i==j==k:
      continue
    elif i == j or A[j]-a > a-A[k]:
      j = k
    if A[j] == 0:
      yield (0, i,j)
    else:
      yield (app(a,A[j]), i,j)


v,i,j = max(it())
print(A[i],A[j])

Submission status: Wrong Answer

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

import bisect
from scipy.misc import comb

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

b = a.pop()
ind = bisect.bisect_left(a, (b+1)//2)
c1 = a[(ind-1)%(n-1)]
c2 = a[ind%(n-1)]
c3 = a[(ind+1)%(n-1)]
maximum = 0
for c_temp in [c1, c2, c3]:
    com = comb(b, c_temp)
    if maximum < com:
        c = c_temp
        maximum = com

print(b, c)

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int,input().split()))
p.sort()
a1 = max(p)
a2 = min(p)
half = a1 // 2
i = 0
s = n // 2
graph = [0] * n

while True:
    if graph[s] != 0:
        break
    else:
        graph[s] += 1
    if p[s] < half:
        if abs(p[s] - half) < abs(a2 - half):
            a2 = p[s]
        s += 1
    elif p[s] > half:
        if abs(p[s] - half) < abs(a2 - half):
            a2 = p[s]
        s -= 1
    if s == 0 or s == n:
        break
print(a1, a2)

Submission status: Wrong Answer

Solution code:
import numpy as np


def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

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

max = max(a)
print(max,getNearestValue(a,max/2))

Submission status: Wrong Answer

Solution code:
from bisect import *

def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError

def find_lt(a, x):
    'Find rightmost value less than x'
    i = bisect_left(a, x)
    try:
        if i:
            return a[i-1]
    except:
        return -1

def find_le(a, x):
    'Find rightmost value less than or equal to x'
    i = bisect_right(a, x)
    try:
        if i:
            return a[i-1]
        else:
            return -1
    except:
        return -1

def find_gt(a, x):
    'Find leftmost value greater than x'
    i = bisect_right(a, x)
    try:
        if i != len(a):
            return a[i]
    except:
        return -1

def find_ge(a, x):
    'Find leftmost item greater than or equal to x'
    i = bisect_left(a, x)
    try:
        if i != len(a):
            return a[i]
        else:
            return -1
    except:
        return -1

def fun(a,b):
    if b==-1:
        return -1
    elif b==0:
        return 0
    return (b+1)*(2*a-b)/2 - b*(b+1)/2

N=int(raw_input())
X=map(int, raw_input().split())
Y=sorted(X)
ans=[-1,0,0]
if len(Y)==2:
    print Y[1],Y[0]

else:
    for y in Y[::-1]:
        qry=y/2
        tmp1=find_ge(Y, qry)
        tmp2=find_le(Y, qry)
        print tmp1,tmp2
        if ans[0]<fun(y,tmp1):
            ans=[fun(y,tmp1),y,tmp1]
        if ans[0]<fun(y,tmp2):
            ans=[fun(y,tmp2),y,tmp2]
    print ans[1], ans[2]

Submission status: Wrong Answer

Solution code:
from bisect import *

def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError

def find_lt(a, x):
    'Find rightmost value less than x'
    i = bisect_left(a, x)
    try:
        if i:
            return a[i-1]
    except:
        return -1

def find_le(a, x):
    'Find rightmost value less than or equal to x'
    i = bisect_right(a, x)
    try:
        if i:
            return a[i-1]
    except:
        return -1

def find_gt(a, x):
    'Find leftmost value greater than x'
    i = bisect_right(a, x)
    try:
        if i != len(a):
            return a[i]
    except:
        return -1

def find_ge(a, x):
    'Find leftmost item greater than or equal to x'
    i = bisect_left(a, x)
    try:
        if i != len(a):
            return a[i]
    except:
        return -1

def fun(a,b):
    if b==-1:
        return -1
    elif b==0:
        return 1
    return (b+1)*(2*a-b)/2 - b*(b+1)/2

N=int(raw_input())
X=map(int, raw_input().split())
Y=sorted(X)
ans=[-1,0,0]
if len(Y)==2:
    print Y[1],Y[0]

else:
    for y in Y[::-1]:
        qry=y/2
        tmp1=find_ge(Y, qry)
        tmp2=find_le(Y, qry)
        if ans[0]<fun(y,tmp1):
            ans=[fun(y,tmp1),y,tmp1]
        if ans[0]<fun(y,tmp1):
            ans=[fun(y,tmp2),y,tmp2]
    print ans[1], ans[2]

Submission status: Wrong Answer

Solution code:
n=int(input())

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

a=max(nums)

diffs=[abs(2*num-a) for num in nums]
min_diff=min(diffs)

b=nums[diffs.index(min_diff)]

print(a,b)

Submission status: Wrong Answer

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

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

a=sorted(C)

M=a[-1]


A=sorted([abs(2*i - M) for i in a])
print(C)
print(a)
print(A)
N1= (-A[0]+M)//2
N2= (A[0]+M)//2
print(N1,N2)
j = C.index(M)
if N1 in a:
    print(M,N1)
else:
    print(M,N2)

Submission status: Wrong Answer

Solution code:
import bisect

n = int(input())
aaa = list(map(int, input().split()))
aaa.sort()
m = aaa[-1]
ri = bisect.bisect(aaa, m // 2)
if ri == 0:
    print(m, aaa[0])
else:
    r1, r2 = aaa[ri - 1], aaa[ri]
    d1 = m - 2 * r1
    d2 = 2 * r2 - m
    if d1 < d2:
        print(m, r1)
    else:
        print(m, r2)

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
ans = 0
al = [ls[-1],ls[0]]
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(n-1,n):
    di = ls[:i]
    di.append(ls[i]//2)
    di.sort()
    ind = di.index(ls[i]//2)
    il,ir = ind,ind
    if ind > 0:
        il -= 1
    else:
        il = -1
    if ind < len(di)-1:
        ir += 1
    else:
        ir = -1
    c = 0
    if ir > 0:
        if il > 0:
            mx = max(combinations_count(ls[i],di[ir]),combinations_count(ls[i],di[il]))
            c = 1
        else:
            mx = combinations_count(ls[i],di[ir])
            c = 3
    else:
        if il > 0:
            mx = combinations_count(ls[i],di[il])
            c = 2
        else:
            mx = 0
    if mx > ans:
        ans = mx
    if ans == mx:
        if c == 1:
            if combinations_count(ls[i],di[ir]) >= combinations_count(ls[i],di[il]):
                al = [ls[i],di[ir]]
            else:
                al = [ls[i],di[il]]
        elif c == 2:
            al = [ls[i],di[il]]
        elif c == 3:
            al = [ls[i],di[ir]]
print(*al)

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
ans = 0
al = [ls[-1],ls[0]]
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(n):
    di = ls[:i]
    di.append(ls[i]//2)
    di.sort()
    ind = di.index(ls[i]//2)
    il,ir = ind,ind
    if ind > 0:
        il -= 1
    else:
        il = -1
    if ind < len(di)-1:
        ir += 1
    else:
        ir = -1
    c = 0
    if ir > 0:
        if il > 0:
            mx = max(combinations_count(ls[i],di[ir]),combinations_count(ls[i],di[il]))
            c = 1
        else:
            mx = combinations_count(ls[i],di[ir])
            c = 3
    else:
        if il > 0:
            mx = combinations_count(ls[i],di[il])
            c = 2
        else:
            mx = 0
    if mx > ans:
        ans = mx
    if ans == mx:
        if c == 1:
            if combinations_count(ls[i],di[ir]) >= combinations_count(ls[i],di[il]):
                al = [ls[i],di[ir]]
            else:
                al = [ls[i],di[il]]
        elif c == 2:
            al = [ls[i],di[il]]
        elif c == 3:
            al = [ls[i],di[ir]]
print(*al)

Submission status: Time Limit Exceeded

Solution code:
import math
import heapq
n = int(input())
ls = list(map(int,input().split()))
ls.sort()
ans = 0
al = [ls[-1],ls[0]]
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(n):
    di = ls[:i]
    heapq.heapify(di)
    heapq.heappush(di,ls[i]//2)
    di.sort()
    ind = di.index(ls[i]//2)
    il,ir = ind,ind
    if ind > 0:
        il -= 1
    else:
        il = -1
    if ind < len(di)-1:
        ir += 1
    else:
        ir = -1
    c = 0
    if ir > 0:
        if il > 0:
            mx = max(combinations_count(ls[i],di[ir]),combinations_count(ls[i],di[il]))
            c = 1
        else:
            mx = combinations_count(ls[i],di[ir])
            c = 3
    else:
        if il > 0:
            mx = combinations_count(ls[i],di[il])
            c = 2
        else:
            mx = 0
    if mx > ans:
        ans = mx
    if ans == mx:
        if c == 1:
            if combinations_count(ls[i],di[ir]) >= combinations_count(ls[i],di[il]):
                al = [ls[i],di[ir]]
            else:
                al = [ls[i],di[il]]
        elif c == 2:
            al = [ls[i],di[il]]
        elif c == 3:
            al = [ls[i],di[ir]]
print(*al)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    
    N = int(input())
    A = set(map(int,input().split()))
    A = sorted(list(A))

    import bisect
    from operator import mul
    from functools import reduce

    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,0]

    for i in range(len(A)-1,-1,-1):
        x = A[i]
        y = A[i]//2

        tmp0=tmp1=tmp2=0

        if y in A:
            tmp0 = cmb(x,y)
        else:
            z = bisect.bisect_left(A,y,hi=max(0,i-1))
            tmp1 = cmb(x,A[z])
            tmp2 = cmb(x,A[max(0,z-1)])

        max_ = [[tmp0,x,y],[tmp1,x,A[z]],[tmp2,x,A[max(0,z-1)]]]
        max_ = sorted(max_,key=lambda x:x[0],reverse=True)

        if ans[0]<max_[0][0]:
            ans = max_[0]
        break
    print(ans[1],ans[2])

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    
    N = int(input())
    A = set(map(int,input().split()))
    A = sorted(list(A))

    import bisect
    from operator import mul
    from functools import reduce

    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,0]

    for i in range(len(A)-1,-1,-1):
        x = A[i]
        y = A[i]//2

        tmp0=tmp1=tmp2=0

        if y in A:
            tmp0 = cmb(x,y)
        else:
            z = bisect.bisect_left(A,y,hi=max(0,i-1))
            tmp1 = cmb(x,A[z])
            tmp2 = cmb(x,A[max(0,z-1)])

        max_ = [[tmp0,x,y],[tmp1,x,A[z]],[tmp2,x,A[max(0,z-1)]]]
        max_ = sorted(max_,key=lambda x:x[0],reverse=True)

        if ans[0]<max_[0][0]:
            ans = max_[0]
    print(ans[1],ans[2])

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def comb(n,r,mod):
  a=1
  b=1
  r = min(r,n-r)
  for i in range(r):
    a = a*(n-i)%mod
    b = b*(i+1)%mod
  return a*pow(b,mod-2,mod)%mod

n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7

a = sorted(a,reverse = True)
ans = 0
j = 0

for i in range(1,n):
  c = comb(a[0],a[i],mod)
  ans = max(ans,c)
  if ans == c:
    j = i
print(a[0],a[j])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
ai = max(A)
aj1 = ai // 2
aj2 = aj1 + (ai % 2)
while True:
    if aj1 in A:
        print(ai, aj1)
        break
    elif aj2 in A:
        print(ai, aj2)
        break
    aj1 -= 1
    aj2 += 1

Submission status: Time Limit Exceeded

Solution code:
from math import factorial as f

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

A = sorted(A)

ans1 = A[-1]
ans2 = 0

c = 0

for i in range(N) :
    a = A[i]
    calc = f(ans1)//(f(a) * f(ans1-a))

    if c < calc :
        ans2 = a
        c = calc

print(ans1,ans2)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce
from bisect import*
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,*a=map(int,open(0).read().split())
a.sort()
b=a.pop()
#print(a)
if n>10:
    x=bisect_left(a,b//2)
    if x>=n-1:
        print(b,a.pop())
    else:
        z=[cmb(b,a[i])for i in range(x-2,x+1)]
        y=max(z)
        print(b,a[x+z.index(y)-1])
elif n==2:
    print(b,*a)
else:
    z=[cmb(b,a[i])for i in range(n-1)]
    y=a[z.index(max(z))]
    print(b,y)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce
from bisect import*
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,*a=map(int,open(0).read().split())
a.sort()
b=a.pop()
#print(a)
if n>10:
    x=bisect_left(a,b//2)
    if x>=n-1:
        print(b,a.pop())
    else:
        z=[cmb(b,a[i])for i in range(x-2,x+1)]
        y=max(z)
        print(b,a[x+z.index(y)-1])
elif n==2:
    print(b,*a)
else:
    z=[cmb(b,a[i])for i in range(n-1)]
    y=a[z.index(max(z))]
    print(b,y)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce

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,*a=map(int,open(0).read().split())
a.sort()
b=a[-1]
if n>10:
    a=a[n//3:n*2//3]
c=[cmb(b,i) for i in a]
print(b,a[c.index(max(c))])

Submission status: Time Limit Exceeded

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


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


x = A.pop()
N -= 1
for i in range(N):
    if A[i] > x // 2:
        break
if comb(x, A[i]) > comb(x, A[i - 1]):
    y = A[i]
else:
    y = A[i - 1]
print(x, y)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import itertools
import numpy as np

def comb(N,k): # from scipy.comb(), but MODIFIED!
    if (k > N) or (N < 0) or (k < 0):
        return 0
    top = N
    val = 1
    while (top > (N-k)):
        val *= top
        top -= 1
    n = 1
    while (n < k+1):
        val /= n
        n += 1
    return val
    
n = int(input())
a = np.array(list(map(int, input().split())))
nrs = list(itertools.combinations(a, 2))
combs = np.zeros(len(nrs))
for i, nr in enumerate(nrs):
    combs[i] = comb(max(nr),min(nr))
    
index = np.argmax(combs)
print(max(nrs[index]),min(nrs[index]))

Submission status: Time Limit Exceeded

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

def comb(N,k): # from scipy.comb(), but MODIFIED!
    if (k > N) or (N < 0) or (k < 0):
        return 0
    top = N
    val = 1
    while (top > (N-k)):
        val *= top
        top -= 1
    n = 1
    while (n < k+1):
        val /= n
        n += 1
    return val
    
n = int(input())
a = list(map(int, input().split()))

nrs = list(itertools.combinations(a, 2))
combs = []
for nr in nrs:
    combs.append(comb(max(nr),min(nr)))

index = combs.index(max(combs))
print(max(nrs[index]),min(nrs[index]))