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: Time Limit Exceeded

Solution code:
import math

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


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

max_value = 0
sort_number_list = sorted(number_list, reverse=True)

for i in range(len(sort_number_list)):
    for j in range(len(sort_number_list)):
        if sort_number_list[i] == sort_number_list[j]:
            continue
        if sort_number_list[i] > sort_number_list[j]:
            combinations_count_value = combinations_count(sort_number_list[i], sort_number_list[j])
            if max_value < combinations_count_value:
                max_value = combinations_count_value
                value_pair = [sort_number_list[i], sort_number_list[j]]

print('{} {}'.format(value_pair[0], value_pair[1]))

Submission status: Time Limit Exceeded

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

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


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

max_value = 0
for i in range(len(number_list)):
    for j in range(len(number_list)):
        if number_list[i] > number_list[j] and number_list[i] != number_list[j]:
            if max_value < combinations_count(number_list[i], number_list[j]):
                max_value = combinations_count(number_list[i], number_list[j])
                value_pair = [number_list[i], number_list[j]]

print('{} {}'.format(value_pair[0], value_pair[1]))

Submission status: Time Limit Exceeded

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

lastNum = max(numList)

if n > 2:
	bestNum = int(lastNum/2)
	searchNum1 = bestNum
	searchNum2 = bestNum
	while True:
		if searchNum1 in numList:
			flg = True
			break
		if searchNum2 in numList:
			flg = False
			break
		searchNum1 += 1
		searchNum2 -= 1

	if flg:
		print(str(lastNum)+" "+str(searchNum1))
	else:
		print(str(lastNum)+" "+str(searchNum2))
else:
	numList = sorted(numList)
	print(str(numList[1])+" "+str(numList[0]))

Submission status: Time Limit Exceeded

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


# def comb(n1, n2):
# 	result = 1
# 	for x in range(n1-n2+1,n1+1):
# 		result = result * x
# 	for x in range(1,n2+1):
# 		result = result / x
# 	return int(result)

numList = sorted(numList)
lastNum = numList[len(numList)-1]

if n > 2:
	bestNum = int(lastNum/2)
	searchNum1 = bestNum
	searchNum2 = bestNum
	while searchNum1 not in numList and searchNum2 not in numList:
		searchNum1 += 1
		searchNum2 -= 1
	if searchNum1-bestNum > bestNum-searchNum2:
		print(str(lastNum)+" "+str(searchNum2))
	else:
		print(str(lastNum)+" "+str(searchNum1))
else:
	print(str(numList[1])+" "+str(numList[0]))

Submission status: Time Limit Exceeded

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


# def comb(n1, n2):
# 	result = 1
# 	for x in range(n1-n2+1,n1+1):
# 		result = result * x
# 	for x in range(1,n2+1):
# 		result = result / x
# 	return int(result)

numList = sorted(numList)
lastNum = numList[len(numList)-1]

if n > 2:
	bestNum = int(lastNum/2)
	searchNum1 = bestNum
	searchNum2 = bestNum
	while searchNum1 not in numList:
		searchNum1 += 1
	while searchNum2 not in numList:
		searchNum2 -= 1
	if searchNum1-bestNum > bestNum-searchNum2:
		print(str(lastNum)+" "+str(searchNum2))
	else:
		print(str(lastNum)+" "+str(searchNum1))
else:
	print(str(numList[1])+" "+str(numList[0]))

Submission status: Time Limit Exceeded

Solution code:
import math
def c(n,r):
    r=min(r,n-r)
    a=math.factorial(n)//(math.factorial(r)*math.factorial(n-r))
    return a
q=1    
N=int(input())
s=list(map(int,input().split()))
n=max(s)
for i in s:
    t=c(n,i)
    if q<=t:
        q=t
        w=str(n)+" "+str(i)
print(w)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = sorted(a)
maxcomb = 0
x=0
def comb(n,r):
    npr = 1
    rp1 = 1
    for i in range(n-r+1,n+1):
        npr *= i
    for j in range(1,r+1):
        rp1 *= j
    return npr // rp1

comb(10,2)

for i in range(0,n):
    if maxcomb < comb(max(b),b[i]):
        maxcomb = comb(max(b),b[i])            
        x=b[i]
print(max(b),x)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = sorted(a)
maxcomb = 0
x=0
y=0
def comb(n,r):
    npr = 1
    rp1 = 1
    for i in range(n-r+1,n+1):
        npr *= i
    for j in range(1,r+1):
        rp1 *= j
    return npr // rp1

comb(10,2)

for i in range(1,n):
    for j in range(0,i):
        if maxcomb < comb(b[i],b[j]):
            maxcomb = comb(b[i],b[j])
            x=b[i]
            y=b[j]
print(x,y)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = sorted(a)
maxcomb = 0
x=0
y=0
def comb(n,r):
    npr = 1
    rp1 = 1
    for i in range(n-r+1,n+1):
        npr *= i
    for j in range(1,r+1):
        rp1 *= j
    return npr // rp1

comb(10,2)

for i in range(1,n):
    for j in range(0,i):
        if maxcomb < comb(b[i],b[j]):
            maxcomb = comb(b[i],b[j])
            x=b[i]
            y=b[j]
print(x,y)

Submission status: Time Limit Exceeded

Solution code:
import math

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

max_comb = 0
max_n = 0
max_r = 0

for i_n in range(n):
    pre_comb = 0
    for i_r in range(n):
        if a_list[i_n] <= a_list[i_r]:
            continue

        comb = math.factorial(a_list[i_n]) // math.factorial(a_list[i_n] - a_list[i_r]) // math.factorial(a_list[i_r])
        if comb > max_comb:
            max_comb = comb
            max_n = a_list[i_n]
            max_r = a_list[i_r]

        if comb < pre_comb:
            break

        pre_comb = comb

print("{0} {1}".format(max_n, max_r))

Submission status: Time Limit Exceeded

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

import bisect, math
def comb(n,r):
  return math.factorial(n) / (math.factorial(r) * math.factorial(n-r))
  
arg_max_i = bisect.bisect_left(a, a[n-1] // 2)

if comb(a[n-1], a[arg_max_i]) < comb(a[n-1], a[arg_max_i-1]):
  arg_max_i -= 1
if arg_max_i == n-1:
  arg_max_i -= 1

print(a[n-1], a[arg_max_i])

Submission status: Time Limit Exceeded

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


mid_dis = [abs(a[n-1] / 2 - a[i]) for i in range(n-1)]
arg_max_i = [i for i in range(n-1) if mid_dis[i] == min(mid_dis)][0]

print(a[n-1], a[arg_max_i])

Submission status: Time Limit Exceeded

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

import math
def comb(n,r):
  return math.factorial(n) / (math.factorial(r) * math.factorial(n-r))
  
mid_dis = [abs(a[n-1] / 2 - a[i]) for i in range(n-1)]
arg_max_i = [i for i in range(n-1) if mid_dis[i] == min(mid_dis)][0]

print(a[n-1], a[arg_max_i])

Submission status: Time Limit Exceeded

Solution code:
import math
def comb(n,r):
	if n < r:
		return 0
	return int(math.factorial(n) / (math.factorial(r) * math.factorial(n-r)))


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

a = sorted(a)

r = 0
maxV = 0
for i in range(max(0,n//2-2),min(n-1,n//2+2)):
	curr = comb(a[-1],a[i])
	if maxV < curr:
		r = a[i]
		maxV = curr

print(a[-1], r)

Submission status: Time Limit Exceeded

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

    def comb(x, y):
        c = 1
        p = 1
        for i in range(y, 0, -1):
            c = c * i
        for i in range(x, x - y, -1):
            p = p * i
        return p / c

    a.sort(reverse=True)
    tmp = 0
    ans = ""
    for i, v in enumerate(a):
        for k in range(i+1, n):
            m = comb(v, a[k])
            if tmp < m:
                tmp = m
                ans = "{0} {1}".format(v, a[k])

    return ans


print(m())

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
p = max(A)
q = p//2
r = p//2

while True:
    if q in A and p != q:
        print(p,q)
        exit(0)
    elif r in A:
        print(p,r)
        exit(0)
    else:
        q+=1
        r-=1

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
p = max(A)
q = p//2
r = p//2
while True:
    if q in A and p != q:
        print(p,q)
        exit(0)
    elif r in A and p != r:
        print(p,r)
        exit(0)
    else:
        q+=1
        r-=1

Submission status: Time Limit Exceeded

Solution code:
def comb(n, r):
  result = 1
  
  for i in range(n, n - r, -1):
    result *= i
  for i in range(r, 1, -1):
    result //= i
  
  return result

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

a.sort()
a.reverse()
max = 0

for i in range(1, n):
  c = comb(a[0], a[i])
  if c > max:
    max = c
  else:
    i -= 1
    break

print(a[0], a[i])

Submission status: Time Limit Exceeded

Solution code:
from decimal import *

def fac(a,b):
    num = 1
    for i in range(a,b+1):
        num *= i
    return num

def comb(i,j):
    case = Decimal(fac(i-j+1,i)) / Decimal(fac(1,j))
    return case

n = int(input())

number_list = list(map(int,input().split()))
number_list.sort()
max_number = max(number_list)
max_case = 0

for number in number_list:
    case = comb(max_number,number)
    if case > max_case :
        max_case = case
        max_case_number = [max_number,number]

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

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
l = sorted(list(map(int, input().split())), reverse=True)
ans = 0
temp = 0
base = l[0]

for i in range(1, n):
  combo = math.factorial(base) / math.factorial(l[i]) / math.factorial(base-l[i])
  if combo > temp:
    temp = combo
    ans = l[i]

print(base, ans)

Submission status: Time Limit Exceeded

Solution code:
import math
n=input()
a=map(int, raw_input().split())
a.sort()
a.reverse()

def comb(N,R):
	return math.factorial(N)/( math.factorial(N-R)*math.factorial(R) )

c=a[0]

b=[0 for i in range(n)]
for i in range(1,n):
	b[i]=abs(a[i]-c/2)

min_b=min(b[1:])

d=[]
for i in range(1,n):
	if b[i]==min_b:
		d.append( (comb(c,a[i]),a[i]) )

print c,sorted(d, key=lambda x:x[0],reverse=True)[0][1]

Submission status: Time Limit Exceeded

Solution code:
def inpl(): return list(map(int, input().split()))
n = int(input())
a = inpl()
#sa = sorted(a)
maximum = max(a)
c = 0
while True:
    if maximum//2-c in a:
        print(maximum, maximum//2-c)
        break
    elif maximum-maximum//2+c in a:
        print(maximum, maximum-maximum//2+c)
        break
    else:
        c += 1

Submission status: Time Limit Exceeded

Solution code:
def inpl(): return list(map(int, input().split()))
n = int(input())
a = inpl()
#sa = sorted(a)
maximum = max(a)

while True:
    c = 0
    if maximum//2-c in a:
        print(maximum, maximum//2)
        break
    elif maximum-maximum//2+c in a:
        print(maximum, maximum-maximum//2+c)
        break
    else:
        c += 1

Submission status: Time Limit Exceeded

Solution code:
import bisect
import math
def binomial(n, k):
    m = min(k,n-k)
    a = 1
    for i in range(m):
        a *= n
        n -=1
    return a//math.factorial(m)

n =  int(input().strip())
nums  = list(map(int, input().strip().split(' ')))
sortedNums = sorted(nums)
candidates = []
for i in nums:
    insert_index  = bisect.bisect_left(sortedNums,int(i/2))
    if(insert_index == n-1):
        candidates.append((i,sortedNums[insert_index-1]))
    elif(i/2 - sortedNums[insert_index] <= sortedNums[insert_index+1] - i/2):
        candidates.append((i,sortedNums[insert_index]))
    else:
        candidates.append((i,sortedNums[insert_index+1]))

minIndex, tmpMax = 0, 0
for index, value in enumerate(candidates):
    b = binomial(value[0],value[1])
    if(tmpMax < b):
        minIndex = index
        tmpMax = b

print(candidates[minIndex][0], candidates[minIndex][1])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
a_i = a[-1]
a_i_2 = a_i / 2.0
b = a[0]
max0 = 0

for i in a:
    if i < a_i_2:
        b = i
    elif i != a_i:
        c = i
        break
    else:
        c = b
        break
from scipy.misc import comb
if comb(a_i, b) > comb(a_i,c):
    max0 = comb(a_i, b)
    a_j = b
else:
    max0 = comb(a_i, c)
    a_j = c

for i in range(1,n-1): 
    b_i = a[i]
    b_i_2 = b_i / 2.0
    b = a[0]
    for i in a:
        if i < b_i_2:
            b = i
        elif i != b_i:
            c = i
            break
        else:
            c = b
            break
    if comb(a_i, b) > comb(a_i,c): 
        max1 = comb(b_i, b)
        b_j = b
    else:
        max1 = comb(b_i, c)
        b_j = c
    if max1 > max0:
        max0 = max1
        a_i = b_i
        a_j = b_j
print("{} {}".format(a_i, a_j))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
maxa = max(a)
mid = n//2
ncomb = 1
tmp = 1
for i in range(maxa, maxa-a[mid], -1):
    ncomb *= i
for j in range(1, a[mid]+1):
    ncomb /= j
for i in range(maxa, maxa-a[mid-1], -1):
    tmp *= i
for j in range(1, a[mid-1]+1):
    tmp /= j
if maxa == a[mid-1]:
    print(maxa, a[mid])
elif maxa == a[mid]:
    print(maxa, a[mid-1])
elif ncomb > tmp:
    print(maxa, a[mid])
else:
    print(maxa, a[mid-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
n=input()
a=map(int, raw_input().split())
a.sort()
a.reverse()

def comb(N,R):
	return math.factorial(N)/( math.factorial(N-R)*math.factorial(R) )



l=1
r=n-1
c=a[0]
for i in range(20):
	if comb(c,a[(l*2+r)/3]) > comb(c,a[(l+r*2)/3]):
		r=(l+r*2)/3
	else:
		l=(l*2+r)/3


if comb(c,a[(l*2+r)/3]) > comb(c,a[(l+r*2)/3]):
	print c,a[(l*2+r)/3]
else:
	print c,a[(l+r*2)/3]

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# hello worldと表示する
# coding: utf-8
# hello worldと表示する
# coding: utf-8
# hello worldと表示する
"""def comb2(n,r):
    if n == 0 or r == 0: 
        return 1
    return comb2(n-1,r-1)+comb2(n-1,r)
def fact(n):
    if n==0:
        return 1
    return n*fact(n-1)
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]"""
def ncr(n, r):
    r = min(r, n - r)
    if r == 0: return 1;
    if r == 1: return n;
    numerator = [n - r + i + 1 for i in range(r)]
    denominator  = [i + 1 for i 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 *= numerator[k]
    return result
#a = cmb(n,r)
ans=0    
N=int(input())
s=list(map(int,input().split()))
t=max(s)
for i in s:
    c=ncr(t,i)
#    c=fact(t)/(fact(i)*fact(t-i))
    if ans<c and t!=i:
        ans=c
        an=i
print(str(t)+" "+str(an))

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
import bisect

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

    A.sort()
    n = A[-1]
    maxc = 0
    fn = factorial(n)
    i = bisect.bisect_left(A, n // 2)
    for r in [A[i-1], A[i]]:
        comb = (fn // factorial(n - r)) // factorial(r)
        if maxc < comb:
            ans = r
            maxc = comb
    print(n, ans)

main()

Submission status: Time Limit Exceeded

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

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

comb = []
ai=[]
aj=[]

A.sort()
A.reverse()

for i in range(0,N):
    if A[i] == 0:
        pass
    else:
        c_n = A[i]
        for j in range(i+1,N):
            if A[j] == 0:
                c_r = A[j]
                ai.append(c_n)
                aj.append(c_r)                 
                comb.append(0)
            else: 
                c_r = A[j]
                ai.append(c_n)
                aj.append(c_r) 
                com = c_n/c_r
                for k in range(1,c_r):
                    com = com * ((c_n-k)/(c_r-k))
                comb.append(com)

max_idx = comb.index(max(comb))

print(ai[max_idx] , aj[max_idx])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import scipy.misc as scm

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

a = sorted(a, reverse=True)

comb = -1
for i in range(n-1):
    if scm.comb(a[i], int(a[i]/2)) <= comb:
        break
    else:
        r_list = a[i+1:]
        tmp_c = -1
        for r in r_list:
            c = scm.comb(a[i], r)
            if tmp_c < c:
                tmp_c = c
                tmp_r = r
        if tmp_c > comb:
            a_i = a[i]
            a_j = tmp_r
            comb = tmp_c
print(a_i, a_j)

Submission status: Time Limit Exceeded

Solution code:
def ncr(n, r):
    r = min(r, n - r)
    if r == 0: return 1;
    if r == 1: return n;
    numerator = [n - r + i + 1 for i in range(r)]
    denominator  = [i + 1 for i 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 *= numerator[k]
    return result

n=int(input())
X=list(map(int,input().split()))
X.sort(reverse=True)
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        res=ncr(X[i],X[j])
        if ans<res:
            X_1=X[i]
            X_2=X[j]
            ans=res
print(X_1,X_2,sep=" ")

Submission status: Time Limit Exceeded

Solution code:
import math

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

max_num=max(a)
middle_num=math.ceil(max_num/2)
middle_num_up=middle_num
middle_num_down=middle_num

if n>2:
    for i in range(n):
        if middle_num_up in a:
            ans=middle_num_up
            break
        if middle_num_down in a:
            ans=middle_num_down
        else:
            middle_num_up+=1
            middle_num_down-=1
else:
    ans=min(a)

print("{} {}".format(max_num,ans))

Submission status: Time Limit Exceeded

Solution code:
import scipy.misc as scm

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

b = sorted(a, reverse=True)

for i in b:
    j = 0
    if(i % 2 == 0):
        m = int(i/2)
    else:
        m = int((i+1)/2)
    while(True):
        if(int(m - j) in b):
            print("%d %d" %(i, int(m - j)))
            break
        if (int(m + j) in b):
            print("%d %d" %(i, int(m + j)))
            break
        j += 1
    break

Submission status: Time Limit Exceeded

Solution code:
def max_comb(m, nums):
    def fact(n):
        if n == 0 or n == 1:
            return 1
        elif n in d:
            return d[n]
        else:
            f = 1
            for i in range(2, n + 1):
                f *= i
            return f

    def product(a, b):
        p = 1
        for i in range(a, b + 1):
            p *= i
        return p
    
    def comb(n, r):
        if r > n - r:
            return product(r + 1, n) // fact(n - r)
        else:
            return product(n - r + 1, n) // fact(r)
        
    sorted_nums = sorted(nums, reverse=True)
    d = dict()
    maximum = 0
    max_pair = None
    for i in range(m - 1):
        for j in range(i + 1, m):
            n = sorted_nums[i]
            r = sorted_nums[j]
            comb = fact(n) // (fact(n - r) * fact(r))
            if comb > maximum:
                maximum = comb
                max_pair = (n, r)
    return max_pair


if __name__ == '__main__':
    m = int(input())
    nums = map(int, input().split())
    print(' '.join(map(str, max_comb(m, nums))))

Submission status: Time Limit Exceeded

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

import math

def main():
    n = int(input())
    a = list(map(int, input().split()))
    m = max(a)
    a.remove(m)

    ans = m
    mx = -1
    for num in a:
        tmp = math.factorial(m) / (math.factorial(num) * math.factorial(m - num))
        if tmp > mx:
            mx = tmp
            ans = num

    print(m)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect
import math
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = [0,0]
max = 0
i = n-1
if n == 2:
	ans[0] = a[1]
	ans[1] = a[0]
else:
	while i > (89999*n//90000-1):
		if a[i]%2 == 0:
			temp = n-1
			while a[i]//2 < a[temp]:
				temp += -1
			
			if a[i] > a[temp-1]:
				if (a[i]//2-a[temp-1]) <= (a[temp+1]-a[i]//2):
					tmax = (math.factorial(a[i]))/(math.factorial(a[i]-a[temp-1])*math.factorial(a[temp-1]))
					if max < tmax:
						max = tmax
						ans[0] = a[i]
						ans[1] = a[temp-1]
				else:
					tmax = (math.factorial(a[i]))/(math.factorial(a[i]-a[temp+1])*math.factorial(a[temp+1]))
					if max < tmax:
						max = tmax
						ans[0] = a[i]
						ans[1] = a[temp+1]
		else:
			temp1 = n-1
			temp2 = n-1
	
			while (a[i]+1)//2 < a[temp1]:
				temp1 += -1
			while (a[i]-1)//2 < a[temp2]:
				temp2 += -1
			
			if a[i] > a[temp1-1]:
				if (a[i]//2-a[temp1-1]) <= (a[temp1+1]-a[i]//2):
					tmax = (math.factorial(a[i]))/(math.factorial(a[i]-a[temp1-1])*math.factorial(a[temp1-1]))
					if max < tmax:
						max = tmax
						ans[0] = a[i]
						ans[1] = a[temp1-1]
				else:
					tmax = (math.factorial(a[i]))/(math.factorial(a[i]-a[temp1+1])*math.factorial(a[temp1+1]))
					if max < tmax:
						max = tmax
						ans[0] = a[i]
						ans[1] = a[temp1+1]
		
			if a[i] > a[temp2-1]:
				if (a[i]//2-a[temp2-1]) <= (a[temp2+1]-a[i]//2):
					tmax = (math.factorial(a[i]))/(math.factorial(a[i]-a[temp2-1])*math.factorial(a[temp2-1]))
					if max < tmax:
						max = tmax
						ans[0] = a[i]
						ans[1] = a[temp2-1]
				else:
					tmax = (math.factorial(a[i]))/(math.factorial(a[i]-a[temp2+1])*math.factorial(a[temp2+1]))
					if max < tmax:
						max = tmax
						ans[0] = a[i]
						ans[1] = a[temp2+1]
		i += -1
print(ans[0],ans[1])

Submission status: Time Limit Exceeded

Solution code:
import bisect
import math
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = [0,0]
max = 0
i = n-1
if n == 2:
	ans[0] = a[1]
	ans[1] = a[0]
else:
	while i > (9999*n//10000-1):
		if a[i]%2 == 0:
			temp = n-1
			while a[i]//2 < a[temp]:
				temp += -1
			
			if a[i] > a[temp-1]:
				if (a[i]//2-a[temp-1]) <= (a[temp+1]-a[i]//2):
					tmax = (math.factorial(a[i]))/(math.factorial(a[i]-a[temp-1])*math.factorial(a[temp-1]))
					if max < tmax:
						max = tmax
						ans[0] = a[i]
						ans[1] = a[temp-1]
				else:
					tmax = (math.factorial(a[i]))/(math.factorial(a[i]-a[temp+1])*math.factorial(a[temp+1]))
					if max < tmax:
						max = tmax
						ans[0] = a[i]
						ans[1] = a[temp+1]
		else:
			temp1 = n-1
			temp2 = n-1
	
			while (a[i]+1)//2 < a[temp1]:
				temp1 += -1
			while (a[i]-1)//2 < a[temp2]:
				temp2 += -1
			
			if a[i] > a[temp1-1]:
				if (a[i]//2-a[temp1-1]) <= (a[temp1+1]-a[i]//2):
					tmax = (math.factorial(a[i]))/(math.factorial(a[i]-a[temp1-1])*math.factorial(a[temp1-1]))
					if max < tmax:
						max = tmax
						ans[0] = a[i]
						ans[1] = a[temp1-1]
				else:
					tmax = (math.factorial(a[i]))/(math.factorial(a[i]-a[temp1+1])*math.factorial(a[temp1+1]))
					if max < tmax:
						max = tmax
						ans[0] = a[i]
						ans[1] = a[temp1+1]
		
			if a[i] > a[temp2-1]:
				if (a[i]//2-a[temp2-1]) <= (a[temp2+1]-a[i]//2):
					tmax = (math.factorial(a[i]))/(math.factorial(a[i]-a[temp2-1])*math.factorial(a[temp2-1]))
					if max < tmax:
						max = tmax
						ans[0] = a[i]
						ans[1] = a[temp2-1]
				else:
					tmax = (math.factorial(a[i]))/(math.factorial(a[i]-a[temp2+1])*math.factorial(a[temp2+1]))
					if max < tmax:
						max = tmax
						ans[0] = a[i]
						ans[1] = a[temp2+1]
		i += -1
print(ans[0],ans[1])

Submission status: Time Limit Exceeded

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

#2. choose maximum number as a_i and remove
ai = max(a)
a.remove(ai)

# 3. choose the nearest number from (a_i/2) as a_j
ideal = int(ai/2)
dist = 0
while 1:
    if (ideal-dist) in a:
        aj = ideal-dist
        break
    if (ideal+1+dist) in a:
        aj = ideal+1+dist
        break
    dist += 1
    
print("{} {}".format(ai, aj))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

def fastcomb(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 *= numerator[k]


    return int(result)


li = list(combinations(a, 2))

def comb(x,y):
    p = [x,y]
    p.sort()
    return fastcomb(p[1], p[0])
    
comblist = [comb(x,y) for x,y in li]

answer = list(li[[i for i,k in enumerate(comblist) if k==max(comblist)][0]])
answer.sort()
answer.reverse()

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

Submission status: Time Limit Exceeded

Solution code:
def max_comb(m, nums):
    def fact(n):
        if n == 0 or n == 1:
            return 1
        elif n in d:
            return d[n]
        else:
            f = 1
            for i in range(2, n + 1):
                f *= i
            return f

    sorted_nums = sorted(nums, reverse=True)
    d = dict()
    maximum = 0
    max_pair = None
    for i in range(m - 1):
        for j in range(i + 1, m):
            n = sorted_nums[i]
            r = sorted_nums[j]
            comb = fact(n) // (fact(n - r) * fact(r))
            if comb > maximum:
                maximum = comb
                max_pair = (n, r)
    return max_pair


if __name__ == '__main__':
    m = int(input())
    nums = map(int, input().split())
    print(' '.join(map(str, max_comb(m, nums))))

Submission status: Time Limit Exceeded

Solution code:
import bisect
import math
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = [0,0]
max = 0
i = n-1
if n == 2:
	ans[0] = a[1]
	ans[1] = a[0]
else:
	while i > (5*n//100):
		if a[i]%2 == 0:
			temp = n-1
			while a[i]//2 < a[temp]:
				temp += -1
			
			if a[i] > a[temp-1]:
				if (a[i]//2-a[temp-1]) <= (a[temp+1]-a[i]//2):
					tmax = (math.factorial(a[i]))/(math.factorial(a[i]-a[temp-1])*math.factorial(a[temp-1]))
					if max < tmax:
						max = tmax
						ans[0] = a[i]
						ans[1] = a[temp-1]
				else:
					tmax = (math.factorial(a[i]))/(math.factorial(a[i]-a[temp+1])*math.factorial(a[temp+1]))
					if max < tmax:
						max = tmax
						ans[0] = a[i]
						ans[1] = a[temp+1]
		else:
			temp1 = n-1
			temp2 = n-1
	
			while (a[i]+1)//2 < a[temp1]:
				temp1 += -1
			while (a[i]-1)//2 < a[temp2]:
				temp2 += -1
			
			if a[i] > a[temp1-1]:
				if (a[i]//2-a[temp1-1]) <= (a[temp1+1]-a[i]//2):
					tmax = (math.factorial(a[i]))/(math.factorial(a[i]-a[temp1-1])*math.factorial(a[temp1-1]))
					if max < tmax:
						max = tmax
						ans[0] = a[i]
						ans[1] = a[temp1-1]
				else:
					tmax = (math.factorial(a[i]))/(math.factorial(a[i]-a[temp1+1])*math.factorial(a[temp1+1]))
					if max < tmax:
						max = tmax
						ans[0] = a[i]
						ans[1] = a[temp1+1]
		
			if a[i] > a[temp2-1]:
				if (a[i]//2-a[temp2-1]) <= (a[temp2+1]-a[i]//2):
					tmax = (math.factorial(a[i]))/(math.factorial(a[i]-a[temp2-1])*math.factorial(a[temp2-1]))
					if max < tmax:
						max = tmax
						ans[0] = a[i]
						ans[1] = a[temp2-1]
				else:
					tmax = (math.factorial(a[i]))/(math.factorial(a[i]-a[temp2+1])*math.factorial(a[temp2+1]))
					if max < tmax:
						max = tmax
						ans[0] = a[i]
						ans[1] = a[temp2+1]
		i += -1
print(ans[0],ans[1])

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math

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

#n=5
#a=[6,9,4,2,11]

b=list(itertools.combinations(a,2))
c=[]
for bi in b:
  bl=list(bi)
  bl.sort()
  c1=[0 for i in range(bl[1])] 
  c4=len(list(itertools.combinations(c1,bl[0])))
  c.append([c4,bl[1],bl[0]])
c.sort()
print(c[len(c)-1][1],c[len(c)-1][2])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
a_i = a[-1]
a_j = a[0]
max = 0
import numpy as np
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

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

from scipy.misc import comb
for i in range(n):
    if a[i]%2 == 0:
        b_j = getNearestValue(a, a[i]/2)
        b1 = comb(a[i], b_j)
        if max < b1 and a[i] > b_j:
            max = b1
            a_i = a[i]
            a_j = b_j
    else:
        b_j = getNearestValue(a, (a[i]-1)/2)
        b1 = comb(a[i], b_j)
        if max < b1 and a[i] > b_j:
            max = b1
            a_i = a[i]
            a_j = b_j
        b_j = getNearestValue(a, (a[i]+1)/2)
        b1 = comb(a[i], b_j)
        if max < b1 and a[i] > b_j:
            max = b1
            a_i = a[i]
            a_j = b_j
print("{} {}".format(a_i, a_j))

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math

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

#n=5
#a=[6,9,4,2,11]

b=list(itertools.combinations(a,2))
c=[]
for bi in b:
  bl=list(bi)
  bl.sort()
  c1=math.factorial(bl[1])
  c2=math.factorial(bl[0])
  c3=math.factorial(bl[1]-bl[0])
  c4=c1//c3//c2
  c.append([c4,bl[1],bl[0]])
c.sort()
print(c[len(c)-1][1],c[len(c)-1][2])