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

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

a.sort(reverse=True)
max_comb = 0
for i in range(min(10, n-1)):
    comb_sum = 0
    for j in a:
        if j < a[i]:
            comb_sum = combinations_count(a[i], j)
            if comb_sum > max_comb:
                max_comb = comb_sum
                comb_n = a[i]
                comb_r = j

print(comb_n, comb_r)

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

a.sort(reverse=True)
max_comb = 0
for i in range(min(100, n-1)):
    comb_sum = 0
    for j in a:
        if j < a[i]:
            comb_sum = combinations_count(a[i], j)
            if comb_sum > max_comb:
                max_comb = comb_sum
                comb_n = a[i]
                comb_r = j

print(comb_n, comb_r)

Submission status: Time Limit Exceeded

Solution code:
import bisect
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


n = int(input())
a = list(map(int, input().split()))
a.sort()
index = bisect.bisect_left(a,a[-1]//2)
x = combinations_count(a[-1],a[index])
y = combinations_count(a[-1],a[index-1])
if x>y:
    print(a[-1],a[index])
else:
    print(a[-1],a[index-1])

Submission status: Time Limit Exceeded

Solution code:
import bisect

def cmb(n,r):
    if r > n:
        return 0
    if n - r < r:
         r = n - r
    if r > n:
        return 0
    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

n = int(input())
a = list(map(int, input().split()))
a.sort()
index = bisect.bisect_left(a,a[-1]//2)
x = cmb(a[-1],a[index])
y = cmb(a[-1],a[index-1])
if x>y:
    print(a[-1],a[index])
else:
    print(a[-1],a[index-1])

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
n=int(input())
a=list(map(int,input().split()))
b=max(a)
a.remove(b)
l=[]
for i in range(n-1):
  l.append([factorial(b)//(factorial(b-a[i])*factorial(a[i])),a[i]])
l.sort(reverse=True)
print(b,l[0][1])

Submission status: Time Limit Exceeded

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):
    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

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

  if ind!=0:
    x=cmb(a[i],a[ind-1])
    y=cmb(a[i],a[ind])
    if x>=y:
      temp=[a[i],a[ind-1],x]
    else:
      temp=[a[i],a[ind],y]
  else:
    temp=[a[i],a[ind],cmb(a[i],a[ind])]

  if ans[2]>=temp[2]:
    ans=ans
  else:
    ans=temp
print(ans[0],ans[1])

Submission status: Time Limit Exceeded

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,0]
#n/2に最も近いrを探して、左右を比較する。
for i in range(1,n):
  temp=0
  ind=bisect.bisect_left(a,a[i]//2)
  

  if ind!=0:
    x=cmb(a[i],a[ind-1])
    y=cmb(a[i],a[ind])
    if x>=y:
      temp=[a[i],a[ind-1],x]
    else:
      temp=[a[i],a[ind],y]
  else:
    temp=[a[i],a[ind],cmb(a[i],a[ind])]

  if ans[2]>=temp[2]:
    ans=ans
  else:
    ans=temp
print(ans[0],ans[1])

Submission status: Time Limit Exceeded

Solution code:
import sys


def alg_combination(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    else:
        denominator = 1
        for i in range(n, n - r, -1):
            denominator = (denominator * i)
        molecule = 1
        for i in range(1, r + 1):
            molecule = (molecule * i)
        return denominator // molecule


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    a.sort()
    mt = 0
    mn = 0
    for i in range(n):
        t = alg_combination(a[-1], a[i])
        if t > mt:
            mn = a[i]
            mt = t
    print(a[-1], mn)


if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
def N(a): #階乗 n!
    ans = 1
    for i in range(1,a+1):
        ans *= i
    return ans

def C(n,k): #組み合わせ nCk
    memo1 = N(n)
    memo2 = N(k)
    memo3 = N(n-k)
    return (memo1)//(memo2*memo3)


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

ans = 0
for i in range(n):
    memo = ans
    ans = max(C(a[n-1],a[i]),ans)
    if ans != memo:
        memo2 = a[i]

print(a[n-1],memo2)

Submission status: Time Limit Exceeded

Solution code:
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
N=int(input())
A=[int(x) for x in input().split()]
A=sorted(A,reverse = True)
answer=0
p=0
q=0
for i in range(N-1):
  for j in range(i+1,N):
    answer=max(answer,cmb(A[i],A[j]))
    if cmb(A[i],A[j])==answer:
      p=A[i]
      q=A[j]
print(p,q)

Submission status: Time Limit Exceeded

Solution code:
# D - Binomial Coefficients

import bisect, math

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

def comb(n, r):
    if n < r:
        return 0
    else:
        tmp = 1
        for i in range(n+1, n-r+1, -1):
            tmp *= i
        return tmp // math.factorial(r)
    
idx = bisect.bisect_left(a, a[-1]//2)

try:
    if idx != n-1:
        tmp = comb(a[-1], a[idx])
        ans = [a[-1], a[idx]]
    else:
        tmp = 0
    if tmp < comb(a[-1], a[idx-1]):
        tmp = comb(a[-1], a[idx-1])
        ans = [a[-1], a[idx-1]]
    if tmp < comb(a[-1], a[idx+1]) and idx+1 != n-1:
        ans = [a[-1], a[idx+1]]
except IndexError:
    pass

print(*ans)

Submission status: Time Limit Exceeded

Solution code:
# D - Binomial Coefficients

import bisect, math

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

def comb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    
idx = bisect.bisect_left(a, a[-1]//2)

try:
    if a[-1] != a[idx]:
        tmp = comb(a[-1], a[idx])
        ans = [a[-1], a[idx]]
    else:
        tmp = 0
    if tmp < comb(a[-1], a[idx-1]) and a[-1] != a[idx-1]:
        tmp = comb(a[-1], a[idx-1])
        ans = [a[-1], a[idx-1]]
    if tmp < comb(a[-1], a[idx+1]) and a[-1] != a[idx+1]:
        ans = [a[-1], a[idx+1]]
except IndexError:
    pass

print(*ans)

Submission status: Time Limit Exceeded

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

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)

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

if combinations_count(a,b1) >= combinations_count(a,b2):
    print(a,b1)
else:
    print(a,b2)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import math
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

N = int(input())
lst = list(map(int, input().split()))
lst.sort()
n = max(lst)
a = bisect.bisect_right(lst, n//2)
x1 = cmb(n, lst[a])
x2 = cmb(n, lst[a-1])
if x1 > x2:
    print(n, lst[a])
else:
    print(n, lst[a-1])

Submission status: Time Limit Exceeded

Solution code:
import bisect
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())
lst = list(map(int, input().split()))
lst.sort()
n = max(lst)
a = bisect.bisect_right(lst, n//2)
x1 = comb(n, lst[a])
x2 = comb(n, lst[a-1])
if x1 > x2:
    print(n, lst[a])
else:
    print(n, lst[a-1])

Submission status: Time Limit Exceeded

Solution code:
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

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

a = sorted(a)
max_a = a[-1]
left_med_a = a[n//2-1]
right_med_a = a[n//2]

if cmb(max_a, left_med_a) < cmb(max_a, right_med_a):
    print(max_a, right_med_a)
else:
    print(max_a, left_med_a)

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

a = sorted(a)
max_a = a[-1]
left_med_a = a[n//2-1]
right_med_a = a[n//2]

if cmb(max_a, left_med_a) < cmb(max_a, right_med_a):
    print(max_a, right_med_a)
else:
    print(max_a, left_med_a)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N = int(input())
An = list(map(int,input().split(' ')))



An.sort()
max_num = An[N-1]

half_val = max_num//2
idx =  bisect.bisect_right(An[0:N-1],half_val)
if idx == 0:
    print(max_num,An[idx])
elif idx == N-1:
    print(max_num,An[idx-1])
else:
    A = combinations_count(max_num,An[idx-1])
    B = combinations_count(max_num,An[idx])
    if A > B:
        print(max_num,An[idx-1])
    else:
        print(max_num,An[idx])

Submission status: Time Limit Exceeded

Solution code:
from scipy.misc import comb
n=int(input())
A=list(map(int,input().split()))

A.sort()
max_,num=0,0
for a in A:
  if max_<comb(A[-1],a):
    max_=comb(A[-1],a)
    num=a
print(A[-1],num)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n = int(input())
a = list(map(int,input().split()))
a.sort()
#b = list(itertools.combinations(a,2))
ans = [0,(0,0)]
#print(b)
for i in range(n-1):
    tmpans = combinations_count(a[-1],a[i])
    if tmpans >= ans[0]:
        ans = [tmpans,(a[-1],a[i])]
        
print(ans[1][0],ans[1][1])

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n = int(input())
a = list(map(int,input().split()))
b = list(itertools.combinations(a,2))
ans = [0,(0,0)]
#print(b)
for i in range(len(b)):
    tmpans = combinations_count(max(b[i][0], b[i][1]),min(b[i][0], b[i][1]))
    if tmpans >= ans[0]:
        ans = [tmpans,(max(b[i][0], b[i][1]),min(b[i][0], b[i][1]))]
        
print(ans[1][0],ans[1][1])

Submission status: Time Limit Exceeded

Solution code:
from scipy.misc import comb
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)[::-1]
#print(A)
cnt = -1
for i in range(N-1):
  for j in range(i+1,N):
    if comb(A[i], A[j], exact=True) > cnt:
      ans = [A[i], A[j]]
      cnt = comb(A[i], A[j], exact=True)
print(*ans)

Submission status: Time Limit Exceeded

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

def comb(a,b):
    return math.factorial(a)//(math.factorial(a-b) * math.factorial(b))

def mid(a):
    if(a%2!=0):
        return (a+1)//2
    else:
        return a//2
#print(a)
for i in range(n-1):
    ai=a[i]
    temp=list(map(lambda x:abs(x-mid(ai)),a[i+1:]))
#    print(temp)
    bi=a[temp.index(min(temp))+i+1]
#    print(str(ai)+":"+str(bi))
    c=comb(ai,bi)
    if(maxconb<c):
        maxconb=c
        ans=[ai,bi]
print(str(ans[0])+" "+str(ans[1]))

Submission status: Time Limit Exceeded

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

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

for i in range(1):
    for j in range(i+1,n):
        comb=combination(a[i], a[j])
        if(maxcomb < comb):
            maxcomb = comb
            ans=[a[i],a[j]]
print(str(ans[0])+" "+str(ans[1]))

Submission status: Time Limit Exceeded

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

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

for i in range(n-1):
    for j in range(i+1,n):
        comb=combination(a[i], a[j])
        if(maxcomb < comb):
            maxcomb = comb
            ans=[a[i],a[j]]
print(str(ans[0])+" "+str(ans[1]))

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
a=list(map(int,input().split()))
a.sort()
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
ans=[a[-1],a[0]]
tmp=0
for i in range(n-1):
    cnt=combinations_count(a[-1],a[i])
    if tmp<cnt:
        ans[1]=a[i]
        tmp=cnt
print(ans[0])
print(ans[1])

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce
import bisect

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())
A = sorted(list(map(int,input().split())))
maxA = max(A)
A.remove(maxA)
idx = bisect.bisect(A,maxA//2)
if idx == len(A):
  print(maxA,A[-1])
elif idx == 0:
  print(maxA, idx)
else:
  if cmb(maxA,A[idx]) > cmb(maxA,A[idx-1]):
    print(maxA,A[idx])
  else:
    print(maxA,A[idx-1])

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

max_cmb = -float('inf')
done = set([])
for i, n in enumerate(A):
  for j in range(i+1,N):
    r = A[j]
    r = min(n-r,r)
    #print(n,r,cmb(n,r))
    if [n,r] in done: continue
    
    tmp_cmb = cmb(n,r)
    if max_cmb < tmp_cmb:
      max_cmb = tmp_cmb
      nr = [n,A[j]]
    
print(*nr)

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 = int(input())
A = list(map(int, input().split()))
maxA = max(A)
tmp = 0
r = 0
for a in A:
    if maxA == a:
        continue
    combA = cmb(maxA, a)
    if tmp < combA:
        tmp = combA
        r = a

print(maxA, r)

Submission status: Time Limit Exceeded

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

import math
import numpy as np

n = int(input().split()[0])
a_list = list(map(int, input().split()))


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


a_list = sorted(a_list)
max_comb = -float("inf")

for i, ai in enumerate(a_list):
    # aiを固定する
    # aiが偶数の場合は、ai/2、
    # aiが奇数の場合は、(ai-1)/2または(ai+1)/2に
    # 一番近い値が答えになる
    if ai % 2 == 0:
        idx = np.abs(np.asarray(a_list) - ai // 2).argmin()
        aj = a_list[idx]
    else:
        target_1 = (ai - 1) // 2
        idx_1 = np.abs(np.asarray(a_list) - target_1).argmin()
        aj = a_list[idx_1]
        target_2 = (ai + 1) // 2
        idx_2 = np.abs(np.asarray(a_list) - target_2).argmin()

        if abs(a_list[idx_1] - target_1) > abs(a_list[idx_2] - target_2):
            aj = a_list[idx_2]

    comb = C(ai, aj)
    if max_comb < comb:
        max_comb = comb
        comb_set = (ai, aj)

ans = "{} {}".format(ai, aj)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from scipy.misc import comb
N = int(input())
a = [int(x) for x in input().split()]
ans1 = max(a)
a.remove(ans1)
maxkouho = -1
ans2 = -1
for k in a:
    kouho = comb(ans1, k, exact=True)
    if kouho > maxkouho:
        ans2 = k
        #print(ans2)
        maxkouho = comb(ans1, k, exact=True)
print(ans1, ans2)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
n = int(input())
a_list = sorted(list(map(int, input().split())))

a_i_index = len(a_list) - 1
a_i = a_list[-1]
max = 0
max_j_index = None

nobori = True

tmp = a_list[0]
koeta = None
for j_index in range(n):
    if a_list[j_index] * 2 > a_i:
        koeta = j_index
        break
    else:
        tmp = j_index

comb = factorial(a_i) / (factorial(a_i - a_list[koeta]) * factorial(a_list[koeta]))
comb2 = 0
if koeta != 0:
    comb2 = factorial(a_i) / (factorial(a_i - a_list[koeta-1]) * factorial(a_list[koeta-1]))


if comb > comb2:
    print(*[a_i,a_list[koeta]])
else:
    print(*[a_i, a_list[koeta-1]])

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
import itertools
n=int(input())
a=list(map(int,input().split()))
a.sort()
#print(a)
c=[i for i in range(1,a[-1]+1)]

ans=0
for i in range(n-1):
    l=len(list(itertools.combinations(c,a[i])))
    if l>=ans:
        ans=l
        z=a[i]

print(a[-1],z)

Submission status: Time Limit Exceeded

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

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

def solve():
    N = int(input())
    As = list(map(int, input().split()))

    # ai > aj
    # C(ai, aj) とするとき、aiは大きければ大きいほどよいので、Asの最大値でよい
    # 問題はajをどう決めるか。とりあえず全探索？

    As.sort()
    n = As[-1]
    ans_i = 0
    max_c = combination_formula(n, As[0])
    for i in range(1, N-1):
        c = combination_formula(n, As[i])
        if c > max_c:
            max_c = c
            ans_i = i

    print(n, As[ans_i])


if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

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

def combination(n, r): #nCrを求める
    if n - r < r:
        r = n - r
    tmp = 1
    for i in range(n - r + 1, n + 1):
        tmp *= i
    for i in range(1, r + 1):
        tmp //= i
    return tmp
# print (a)

j = bisect_left(a, a[-1]//2)
# print (j)
tmp = combination(a[-1], a[j])
ans1 = a[-1]
ans2 = a[j]
if j != 0:
    if tmp <= combination(a[-1], a[j - 1]):
        ans2 = a[j - 1]

print (ans1, ans2)

Submission status: Time Limit Exceeded

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

import math
from collections import defaultdict

# 組み合わせ
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

A.sort(reverse=True)

max_v = 0
ans = 0
for i in range(N-1):
    memo = defaultdict(int)
    for j in range(i+1, N):
        if memo[A[j]] > 0:
            continue

        x = combinations_count(A[i], A[j])
        memo[A[j]] = x
#        print(x, A[i], A[j])
        if x > max_v:
            max_v = x
            ans = (A[i], A[j])

print(*ans)

Submission status: Time Limit Exceeded

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

import math

# 組み合わせ
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

A.sort(reverse=True)

max_v = 0
ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        x = combinations_count(A[i], A[j])
#        print(x, A[i], A[j])
        if x > max_v:
            max_v = x
            ans = (A[i], A[j])

print(*ans)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
n = int(input())
a_list = sorted(list(map(int, input().split())))

a_i_index = len(a_list) - 1
a_i = a_list[-1]
max = 0
max_j_index = None
for j_index in range(n):
    a_j = a_list[j_index]
    comb = factorial(a_i) / (factorial(a_i - a_j) * factorial(a_j))
    if comb > max:
        max = comb
        max_j_index = j_index
print(a_i, " ", a_list[max_j_index])

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
from math import factorial
from functools import lru_cache

def fact(x: int):
    if(x == 0 or x == 1):
        return 1
    if(dp[x] != 0):
        return dp[x]
    else:
        dp[x] = x * fact(x-1)
        
    return dp[x]

# @lru_cache(maxsize=1000000000)
def comb(n: int, r: int):
    # return fact(n) // (fact(r)*fact(n-r))
    return factorial(n) // (factorial(r)*factorial(n-r))


# dp = [0] * 1000000000

def solve(n: int, a: "List[int]"):
    a.sort()

    ai,aj = 0,0
    ans = 0
    for i in range(n-1, -1, -1):
        t = a[i] / 2
        from bisect import bisect_left, bisect_right
        nx = bisect_left(a, t)-1
        j = nx
        if(0 <= nx+1 <= n-1 and abs(a[nx]-t) > abs(a[nx+1]-t)):
            j = nx+1
        c = comb(a[i], a[j])
        if(c > ans):
            ai, aj = a[i], a[j]
            ans = c
            
    print(ai,aj)
    
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
from math import factorial
from functools import lru_cache

def fact(x: int):
    if(x == 0 or x == 1):
        return 1
    if(dp[x] != 0):
        return dp[x]
    else:
        dp[x] = x * fact(x-1)
        
    return dp[x]

@lru_cache(maxsize=1000000000)
def comb(n: int, r: int):
    # return fact(n) // (fact(r)*fact(n-r))
    return factorial(n) // (factorial(r)*factorial(n-r))


# dp = [0] * 1000000000

def solve(n: int, a: "List[int]"):
    a.sort()

    ai,aj = 0,0
    ans = 0
    for i in range(n-1, -1, -1):
        p = n // 2
        if(p == 0):
            p = p+1
        elif(p == n-1):
            p = p-1
        x = a[p]
        while(True):
            if(a[i] > a[p]):
                if(0 < p < n and comb(a[i], a[p-1]) > comb(a[i], a[p])):
                    p = p-1
                elif (0 <= p < n-1 and comb(a[i], a[p+1]) > comb(a[i], a[p])):
                    p = p+1
                else:
                    if(comb(a[i],a[p]) > ans):
                        ans = comb(a[i],a[p])
                        ai,aj = a[i],a[p]
                    break
                
            else:
                break
    
    print(ai,aj)
    
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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: Time Limit Exceeded

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

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

def solve(n: int, a: "List[int]"):
    a.sort()

    ai,aj = 0,0
    ans = 0
    for i in range(n-1, -1, -1):
        p = n // 2
        if(p == 0):
            p = p+1
        elif(p == n-1):
            p = p-1
        x = a[p]
        while(True):
            if(a[i] > a[p]):
                if(0 < p < n and comb(a[i], a[p-1]) > comb(a[i], a[p])):
                    p = p-1
                elif (0 <= p < n-1 and comb(a[i], a[p+1]) > comb(a[i], a[p])):
                    p = p+1
                else:
                    if(comb(a[i],a[p]) > ans):
                        ans = comb(a[i],a[p])
                        ai,aj = a[i],a[p]
                    break
                
            else:
                break
    
    print(ai,aj)
    
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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: Time Limit Exceeded

Solution code:
import math

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

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

imax = a[0]
jmax = 0
cmax = 0


for j in range(n//2, n//2+1):
    tmp = comb(a[0], a[j])
    if cmax < tmp:
        cmax = tmp
        jmax = a[j]

print(imax, jmax)

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

imax = 0
jmax = 0
cmax = 0

for i in range(n-1):
    for j in range(i+1, n):
        tmp = comb(a[i], a[j])
        if cmax < tmp:
            cmax = tmp
            imax = a[i]
            jmax = a[j]

print(imax, jmax)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
n = int(input())
a_list = sorted(list(map(int, input().split())))

a_i_index = len(a_list) - 1
a_i = a_list[-1]
max = 0
max_j_index = None
for j_index in range(n):
    a_j = a_list[j_index]
    comb = factorial(a_i) / (factorial(a_i - a_j) * factorial(a_j))
    if comb > max:
        max = comb
        max_j_index = j_index
print(a_i, " ", a_list[max_j_index])

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce
n = int(input())
a = list(map(int,input().split()))
m = max(a)
cnt = 0
ans = 0

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
  
for num in a:
  cal = cmb(m, num)
  if cal >= cnt:
    cnt = cal
    ans = num
print(m,ans)

Submission status: Time Limit Exceeded

Solution code:
import math

def C(a,b):
    return math.factorial(a) // (math.factorial(b)*math.factorial(a-b))

def check(ans, ansC, *args):
    n = len(args)
    temp = []
    for i in range(n):
        temp.append(C(args[i][0], args[i][1]))
    ind = temp.index(max(temp))
    temp += [ansC]
    if ind == n:
        return ans, ansC
    else:
        return args[ind - 1], temp[ind]

n = int(input())
a = sorted(list(map(int, input().split())))
ans, ansC = [1, 0], 1

while len(a) > 1:
    A = a.pop(-1)
    if A//2 in a:
        ans, ansC = check(ans, ansC, [A, A//2])
        break
    elif A % 2 != 0 and A//2 + 1 in a:
        ans, ansC = check(ans, ansC, [A, A//2 + 1])
        break
    elif ansC > C(A, A//2):
        break
    else:
        x, i = A//2, 0
        if a[-1] < x:
            ans, ansC = check(ans, ansC, [A, a[-1]])
        else:
            while a[i] < x:
                i += 1
            ans, ansC = check(ans, ansC, [A, a[i]], [A, a[i-1]])

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