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:
N = int(input())
A = list(map(int,input().split()))
maxA = max(A)
B = [abs(i-maxA/2) for i in A]
mid_pA = int(min(B) + maxA/2)
mid_mA = int(-min(B) + maxA/2)
for i in A:
    if i == mid_pA:
        print(maxA,mid_pA)
        break
    elif i == mid_mA:
        print(maxA,mid_mA)
        break

Submission status: Wrong Answer

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]
for i in a:
    if i < a_i_2:
        b = i
    else:
        c = i
        break
from scipy.misc import comb
if comb(a_i, b) > comb(a_i,c):
    print("{} {}".format(a_i, b))
else:
    print("{} {}".format(a_i, c))

Submission status: Wrong Answer

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

amax = max(ali)
b=min(ali,key=lambda x: abs(2*x-amax))
print(amax,end=' ')
print(b)

Submission status: Wrong Answer

Solution code:
import math
n=int(input().rstrip())
A=list(map(int, input().rstrip().split())) #input parameters
A.sort()
work=int()
bestr=int()
def comb(x,y):
    return(math.factorial(x)/(math.factorial(x-y)*math.factorial(y)))
for i in range(n-2):
    if comb(A[n-1],A[i-1])>work:
        work=comb(A[n-1],A[i-1])
        bestr=A[i-1]
print("{0} {1}".format(A[n-1],bestr))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
maxA = max(A)
half = maxA/2
t = 100000009
for i in range(N):
    if A[i] != maxA and abs(A[i]-half) < abs(t-half):
        t = A[i]
print(maxA,t)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
maxA = max(A)
half = maxA/2
t = 100000009
for i in range(N):
    if abs(A[i]-half) < abs(t-half):
        t = A[i]
print(maxA,t)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
maxA = max(A)
half = maxA/2
t = 100000009
for i in range(N):
    print("i",i,"t",t,"Ai",A[i],)
    if abs(A[i]-half) < abs(t-half):
        t = A[i]
print(maxA,t)

Submission status: Wrong Answer

Solution code:
# coding : utf-8

import numpy as np

N = int(input())
X = np.array([int(i) for i in input().split()])

maxl = np.max(X)
Xed = X - int(maxl/2)
com = X[np.where(np.min(Xed))]

print(maxl,com[0])

Submission status: Wrong Answer

Solution code:
n = input()
a = map(int, raw_input().split())
a.sort()
x = a[-1]
s = x
p = a[0]
for i in a:
    if s >= abs((x/2)-i):
        s = (x/2)-i
        p = i
    else:
        print x, p
        break

Submission status: Wrong Answer

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

def fac(x):
 fact = 1
 for f in range(1, x+1):
  fact *= f
 return fact

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

maxi = (1, 1)
for i in a:
 for j in a:
  if i < j: continue
  maxi = (i, j) if comb(*maxi) < comb(i, j) else maxi
print(*maxi)

Submission status: Wrong Answer

Solution code:

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

def f(N, A):
    
    if len(A) == 2:
        A.sort()
        print(A[1], A[0])
        return

    maxA = max(A)
    res = 0
    
    for a in A:
        if a == maxA:
            continue
        
        b = min(a, maxA - a)
        if res < b:
            res = b
        
    return print(maxA, res)

f(N, A)

Submission status: Wrong Answer

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

n = int(raw_input())
l = map(int, raw_input().split())

l.sort()

n = l[-1:][0]
# Comb(n,r) = n!/((n-r)!*r!)

def factorial(n):
    buff = n
    c_n = 1
    while buff > 0:
        c_n = c_n * n
        buff = buff - 1
    return c_n

i = 0
flag = True
while i < len(l):
    if i == len(l) - 1: 
        break
    c1 = (n - l[i+1]) * l[i+1]
    c2 = (n - l[i]) * l[i]
    if c1 < c2:
        break
    i = i + 1

print("{} {}".format(n,l[i]))

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
if n == 2:
    print(max(a),min(a))
    exit()
ans_n = a[n-1]
bestr = ans_n//2
kouho = bisect.bisect_left(a,bestr)
if abs(bestr-a[kouho-1]) > abs(bestr-a[kouho]):
    ans_r = a[kouho-1]
else:
    ans_r = a[kouho]
print(ans_n, ans_r)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
x = max(A)
y = 1e9
x2 = x/2
for a in sorted(A):
    if abs(x2 - a) < abs(x2 - y):
        y = a
        print(x, y, abs(x/2 - a))
    else:
        break
print(x, y)

Submission status: Time Limit Exceeded

Solution code:
from scipy.special import comb
n = int(input())
aa = list(map(int, input().split()))
list1 = []

for j in range(n):
  for i in range(j+1, n):
    list1.append([comb(aa[i], aa[j]), aa[i],aa[j]])
    
ma = max(list1, key= lambda x:x[0])
ans = sorted([ma[1], ma[2]], reverse = True)

print(*ans)

Submission status: Time Limit Exceeded

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

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

maxi = 0
i = n-1
key = a[i] // 2
ok = n
ng = -1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if key <= a[mid]: ok = mid
    else: ng = mid
if ok < i: 
    if comb(a[i], a[ok]) > maxi:
        maxi = comb(a[i], a[ok])
        ans = [a[i], a[ok]]
if ng >= 0: 
    if comb(a[i], a[ng]) > maxi:
        maxi = comb(a[i], a[ng])
        ans = [a[i], a[ng]]
print("{} {}". format(ans[0], ans[1]))

Submission status: Time Limit Exceeded

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

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

maxi = 0
# print(n*99//100)
for i in range(n-1, n-2, -1):
    key = a[i] // 2
    ok = n
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if key <= a[mid]: ok = mid
        else: ng = mid
    if ok < i: 
        if comb(a[i], a[ok]) > maxi:
            maxi = comb(a[i], a[ok])
            ans = [a[i], a[ok]]
    if ng >= 0: 
        if comb(a[i], a[ng]) > maxi:
            maxi = comb(a[i], a[ng])
            ans = [a[i], a[ng]]
print("{} {}". format(ans[0], ans[1]))

Submission status: Time Limit Exceeded

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

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

maxi = 0
# print(n*99//100)
for i in range(n-1, n*9999//10000-1, -1):
    key = a[i] // 2
    ok = n
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if key <= a[mid]: ok = mid
        else: ng = mid
    if ok < i: 
        if comb(a[i], a[ok]) > maxi:
            maxi = comb(a[i], a[ok])
            ans = [a[i], a[ok]]
    if ng >= 0: 
        if comb(a[i], a[ng]) > maxi:
            maxi = comb(a[i], a[ng])
            ans = [a[i], a[ng]]
print("{} {}". format(ans[0], ans[1]))

Submission status: Time Limit Exceeded

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

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

maxi = 0
# print(n*99//100)
for i in range(n-1, n*99//100-1, -1):
    key = a[i] // 2
    ok = n
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if key <= a[mid]: ok = mid
        else: ng = mid
    if ok < i: 
        if comb(a[i], a[ok]) > maxi:
            maxi = comb(a[i], a[ok])
            ans = [a[i], a[ok]]
    if ng >= 0: 
        if comb(a[i], a[ng]) > maxi:
            maxi = comb(a[i], a[ng])
            ans = [a[i], a[ng]]
print("{} {}". format(ans[0], ans[1]))

Submission status: Time Limit Exceeded

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

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

maxi = 0
for i in range(1, n):
    key = a[i] // 2
    ok = n
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if key <= a[mid]: ok = mid
        else: ng = mid
    if ok < i: 
        if comb(a[i], a[ok]) > maxi:
            maxi = comb(a[i], a[ok])
            ans = [a[i], a[ok]]
    if ng >= 0: 
        if comb(a[i], a[ng]) > maxi:
            maxi = comb(a[i], a[ng])
            ans = [a[i], a[ng]]
print("{} {}". format(ans[0], ans[1]))

Submission status: Time Limit Exceeded

Solution code:
from math import factorial

N = int(input())
AS = [int(i) for i in input().split()]
m = max(AS)

cache = [1]
for i in range(1, m+1):
  cache.append(i * cache[i-1])

def comb(n, r):
  return cache[n] / cache[r] / cache[n-r]

a = 0
x = None
for e in (a for a in AS if a != m):
  c = comb(m, e)
  if a < c:
    a = c
    x = e


print(m, x)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
N = int(input())
A = list(map(int, input().split()))


def comb(n, k):
    if k > n//2:
        k = n-k
    c, d = 1, 1
    for i in range(k):
        c *= n-i
        d *= i+1
    return c//d


A.sort()
a = A[-1]
k = bisect_left(A, a//2+1)
x = comb(a, A[k-1])
y = comb(a, A[k])
if x >= y:
    b = A[k-1]
else:
    b = A[k]
print(a, b)

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
ans = 0
for i in range(n):
    if ans < math.factorial(a[-1]) // (math.factorial(a[i]) * math.factorial(a[-1] - a[i])):
        keep = a[i]
        ans = math.factorial(a[-1]) // (math.factorial(a[i]) * math.factorial(a[-1] - a[i]))
print(a[-1], keep)

Submission status: Time Limit Exceeded

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

b = []
for i in range(N - 1):
    x = a[i] // 2
    l = i + 1
    r = N - 1
    while r - l > 1:
        mid = l + (r - l) // 2
        if a[mid] < x:
            r = mid
        else:
            l = mid
    if abs(x - a[l]) <= abs(x - a[r]):
        b.append([a[i], a[l]])
    else:
        b.append([a[i], a[r]])

t = 0
ans = 0

for i in range(len(b)):
    tmp = combinations_count(b[i][0], b[i][1])
    if t < tmp:
        t = tmp
        ans = i

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

a_list = list(map(int, input().split()))
a_list.sort()
a_max = a_list[n-1]
temp_max = [1, 0]
bunbo = 1
bunshi = 1
candidate = []
a_set = set(a_list)
for i in range(a_max):
    if i == 0:
        continue
    bunbo *= max(1, i)
    bunshi *= max(1, a_max-i+1)
    if i in a_set:
        if bunshi//bunbo > temp_max[0]:
            temp_max = [bunshi//bunbo, i]

print(a_max, temp_max[1])

Submission status: Time Limit Exceeded

Solution code:
from math import *
N = int(input())
A = sorted(list(map(int,input().split())))
B = A[-1]
C = 0

for a in A:
  if C<comb(B,a):
    C = comb(B,a)
    ans = [A[-1],a]

print(*ans)

Submission status: Time Limit Exceeded

Solution code:
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()))
if N==2:
    print(*A)
else:
    A=sorted(A)
    ans1=A[-1]
    del A[-1]
    saidai=ans1/2
    left=0
    right=N-2
    while right-left>1:
        mid=(left+right)//2
        if A[mid]>=saidai:
            right=mid
        else:
            left=mid
    r=combinations_count(ans1,A[right])
    l=combinations_count(ans1,A[left])
    if r>=l:
        print(ans1,A[right])
    else:
        print(ans1,A[left])

Submission status: Time Limit Exceeded

Solution code:
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()))
if N==2:
    print(*A)
else:
    A=sorted(A)
    ans1=A[-1]
    num=0
    flag=0
    for n in range(N-1):
        if combinations_count(ans1,A[n])>=num:
            num=combinations_count(ans1,A[n])
        else:
            flag=1
            break
    if flag==1:
        print(ans1,A[n-1])
    else:
        print(ans1,A[-2])

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce


def calc_comb(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


def main():
    n = int(input())
    a = [int(an) for an in input().split()]
    a.sort()
    ans = 0
    max_comb = 0
    sub_set = set()
    for i in range(n - 1):
        sub = a[-1] - a[i]
        if not sub in sub_set:
            sub_set.add(sub)
            comb = calc_comb(a[-1], a[i])
            if comb > max_comb:
                max_comb = comb
                ans = a[i]
    print(f'{a[-1]} {ans}')


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# from math import factorial
from operator import mul
from functools import reduce


def calc_comb(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


def main():
    n = int(input())
    a = [int(an) for an in input().split()]
    a.sort()
    ans1 = 0
    ans2 = 0
    max_comb = 0
    for i in range(1, n):
        sub_set = set()
        for j in range(i):
            sub = a[i] - a[j]
            if not sub in sub_set:
                sub_set.add(sub)
                # comb = factorial(a[i]) // (factorial(sub) * factorial(a[j]))
                comb = calc_comb(a[i], a[j])
                if comb > max_comb:
                    max_comb = comb
                    ans1 = a[i]
                    ans2 = a[j]
    print(f'{ans1} {ans2}')


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from math import factorial


def calc_comb(n, r):
    return factorial(n) // (factorial(n - r) + factorial(r))


def main():
    n = int(input())
    a = [int(an) for an in input().split()]
    a.sort()
    ans1 = 0
    ans2 = 0
    max_comb = 0
    for i in range(1, n):
        sub_set = set()
        for j in range(i):
            sub = a[i] - a[j]
            if not sub in sub_set:
                sub_set.add(sub)
                comb = factorial(a[i]) // (factorial(sub) * factorial(a[j]))
                if comb > max_comb:
                    max_comb = comb
                    ans1 = a[i]
                    ans2 = a[j]
    print(f'{ans1} {ans2}')


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

from scipy.special import comb

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

a.sort()

value = comb(a[1], a[0], exact=True)
ans = [a[1], a[0]]
index = 0
for i in range(2, n):
    value_tmp = comb(a[i], a[index], exact=True)
    x = a[i]
    y = a[index]
    diff = abs((x-2*y)//2)
    while 1:
        y_new = a[index+1]
        diff_new = abs((x-2*y_new)//2)
        if diff_new > diff:
            break
        else:
            index += 1
    if value_tmp > value:
        ans = [a[i], a[index]]
        # value = value_tmp
print(*ans)

Submission status: Time Limit Exceeded

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

from scipy.special import comb

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


a.sort()

value = comb(a[1], a[0], exact=True)
ans = [a[1], a[0]]
index = 0
for i in range(2, n):
    value_tmp = comb(a[i], a[index], exact=True)
    while 1:
        tmp = comb(a[i], a[index+1], exact=True)
        if value_tmp > tmp:
            break
        else:
            value_tmp = tmp
            index += 1
    if value_tmp > value:
        ans = [a[i], a[index]]
        value = value_tmp
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
import math


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

ans = []
for i in range(n-1):
  for j in range(i+1, n):
    if a[j] > a[i]:
      res = math.factorial(a[j])//(math.factorial(a[i])*math.factorial(a[j-i]))
      ans.append((res, a[j], a[i]))
#print(max(ans))
print(max(ans)[1], max(ans)[2])

Submission status: Time Limit Exceeded

Solution code:
from scipy.special import comb

n = int(input())
a = sorted(list(map(int, input().split())))
num0, num1, val = 0, 0, 0

if n == 2:
    print(a[1], a[0])
else:
    for i in range(n-1, n//2, -1):
        for j in range(i-1, 0, -1):
            val0 = comb(a[i], a[j])
            if val0 > val:
                num0 = a[i]
                num1 = a[j]
                val = val0
    print(num0, num1)

Submission status: Time Limit Exceeded

Solution code:
from scipy.special import comb

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

# N=2の時は組み合わせは1つしかない
if N == 2:
    print(A[0], A[1])
    exit(0)


A.sort()
n = A[-1]
mid = n//2
idx = 0
ans_abs = 10**9
for i in range(N-1):
    if ans_abs > abs(mid-A[i]):
        ans_abs = abs(mid-A[i])
        idx = i

cmb = comb(n, A[idx], exact=True)
cmb_h = comb(n, A[idx+1], exact=True)
cmb_l = 0
if idx > 0:
    cmb_l = comb(n, A[idx-1], exact=True)

max_cmb = max(cmb, cmb_l, cmb_h)
if cmb == max_cmb:
    print(n, A[idx])
elif cmb_l == max_cmb:
    print(n, A[idx-1])
else:
    print(n, A[idx+1])

Submission status: Time Limit Exceeded

Solution code:
from scipy.special import comb
import bisect

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

# N=2の時は組み合わせは1つしかない
if N == 2:
    print(A[0], A[1])
    exit(0)


A.sort()
n = A[-1]

# 二分探査で最大値を求める
r = 0
mid_idx = N//2
while True:
    mid_comb = comb(n, A[mid_idx], exact=True)
    mid_h_comb = comb(n, A[mid_idx+1], exact=True)
    mid_l_comb = comb(n, A[mid_idx-1], exact=True)

    # 初期値の真ん中が答えだった場合
    if mid_comb == max(mid_comb, mid_h_comb, mid_l_comb):
        r = A[mid_idx]
        break

    # 次の中央値を求める
    if mid_comb < mid_h_comb:
        mid_idx = (mid_idx+N)//2
    else:
        mid_idx = mid_idx//2

print(n, r)

Submission status: Time Limit Exceeded

Solution code:
from scipy.special import comb


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

A.sort()
n = A[-1]

before_cmb = -1
max_cmb = -1
r = 0
for i in range(N):
    tmp_cmb = comb(n, A[i], exact=True)
    if max_cmb < tmp_cmb:
        max_cmb = tmp_cmb
        r = A[i]

    if before_cmb == -1:
        before_cmb = tmp_cmb
    elif before_cmb >= tmp_cmb:
        break

    before_cmb = tmp_cmb
print(n, r)

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.sort()
n = A[-1]

before_cmb = -1
max_cmb = -1
r = 0
for i in range(N):
    tmp_cmb = cmb(n, A[i])
    if max_cmb < tmp_cmb:
        max_cmb = tmp_cmb
        r = A[i]

    if before_cmb == -1:
        before_cmb = tmp_cmb
    elif before_cmb >= tmp_cmb:
        break

    before_cmb = tmp_cmb
print(n, r)

Submission status: Time Limit Exceeded

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

ai = a[-1]
half_ai = ai // 2

i_left = bisect.bisect_left(a, half_ai)
i_right = bisect.bisect_right(a, half_ai)
if (a[i_left] == half_ai):
    print(ai, half_ai)
    exit()

le = (math.factorial(ai) // math.factorial(ai -
                                           a[i_left - 1])) // math.factorial(a[i_left - 1])
ri = (math.factorial(ai) // math.factorial(ai - \
      a[i_right])) // math.factorial(a[i_right])

if (le >= ri):
    print(ai, a[i_left - 1])
else:
    print(ai, a[i_right])

Submission status: Time Limit Exceeded

Solution code:
import math
from collections import defaultdict
d = defaultdict(str)
n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)

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


ai = a[0]
ai_fct = math.factorial(ai)
max_fct = 0
for i in range(n):
    if (i == 0):
        continue
    fct = cmb(a[0], a[i])
    d[fct] = str(ai) + ' ' + str(a[i])
    max_fct = max(max_fct, fct)

print(d[max_fct])

Submission status: Time Limit Exceeded

Solution code:
import math
from collections import defaultdict
d = defaultdict(str)
n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)

ai = a[0]
ai_fct = math.factorial(ai)
max_fct = 0
for i in range(n):
    if (i == 0):
        continue
    fct = (ai_fct // math.factorial(a[i])) // math.factorial(ai - a[i])
    d[fct] = str(ai) + ' ' + str(a[i])
    max_fct = max(max_fct, fct)

print(d[max_fct])

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools

def swap(a,b):
    return max(a,b),min(a,b)

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

N = int(input())
an = list(map(int,input().split()))
#an = [5,10,12]
an.sort()

max_v = 0
max_e = None
for i in an[:-1]:
    n,r = swap(an[-1], i)
    v = comb(n,r)
    if v > max_v:
        max_v = v
        max_e = (n,r)
    #print(c, comb(*c))

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

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools

def swap(a,b):
    return max(a,b),min(a,b)

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

N = int(input())
an = list(map(int,input().split()))
#an = [5,10,12]
an.sort()

max_v = 0
max_e = None
for c in itertools.combinations(an, 2):
    n,r = swap(*c)
    v = comb(n,r)
    if v > max_v:
        max_v = v
        max_e = (n,r)
    #print(c, comb(*c))

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

Submission status: Time Limit Exceeded

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

cnt = 0
ans = [a[0], a[1]]
for i in range(n-1):
  num = a[i]
  tmp = a[i+1]
  for j in range(i+1, n):
    if abs(tmp-num/2) >= abs(a[j]-num/2):
      tmp = a[j]
    else:
      break
  if abs(tmp-num/2) < 1:
    ans = [num, tmp]
    break
  mul = math.factorial(num) // (math.factorial(tmp)*math.factorial(num-tmp))
  if cnt < mul:
    cnt = mul
    ans = [num, tmp]
print(*ans)

Submission status: Time Limit Exceeded

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

cnt = 0
ans = [a[0], a[1]]
for i in range(n-1):
  num = a[i]
  half = num // 2
  mx = math.factorial(num) // (math.factorial(half)*math.factorial(num-half))
  if cnt > mx:
    break
  tmp = a[i+1]
  for j in range(i+1, n):
    if abs(tmp-num/2) >= abs(a[j]-num/2):
      tmp = a[j]
    else:
      break
  mul = math.factorial(num) // (math.factorial(tmp)*math.factorial(num-tmp))
  if cnt < mul:
    cnt = mul
    ans = [num, tmp]
  if abs(a[j]-num/2) < 1:
    break
print(*ans)

Submission status: Time Limit Exceeded

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

cnt = 0
ans = [a[0], a[1]]
for i in range(n-1):
  num = a[i]
  half = num // 2
  mx = math.factorial(num) // (math.factorial(half)*math.factorial(num-half))
  if cnt > mx:
    break
  tmp = a[i+1]
  for j in range(i+1, n):
    if abs(tmp-num/2) >= abs(a[j]-num/2):
      tmp = a[j]
    else:
      break
  mul = math.factorial(num) // (math.factorial(tmp)*math.factorial(num-tmp))
  if cnt < mul:
    cnt = mul
    ans = [num, tmp]
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np

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

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

n = int(input())
a = [int(i) for i in input().split()]
check = 0
a.sort()
for i in range(1,n):
    b = a[-i]
    c = getNearestValue(a,b/2)
    an = combinations_count(b,c)
    if check < an:
        check = an
        ans = str(b) + ' ' + str(c)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
p = 10**9+7
f=[1]
for i in range(1,a[0]+1):
  f.append(f[-1] * i)

def nCk(n,k):
  return (f[n] * pow(f[n-k],p-2,p) * pow(f[k],p-2,p)) % p

start = 0
end = -1
ans = 0
for i in range(1,n):
  t = nCk(a[start], a[i])
  if ans < t:
    ans = t
    end = i
print(a[start], a[end])

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

x = max(a)
a.remove(x)
a.sort()
ans = 0
for i in a:
    y = cmb(x, i)
    if ans <= y:
        ans = y
    else:
        break    
    z = i
      
print(x, z)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

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

def cmb(n, r):
    INF = 10 ** 9 + 7
    r = min(n - r, r)
    if r == 0:  return 1
    numer = reduce(lambda x, y: (x * y) % INF, range(n, n - r, -1))
    denom = reduce(lambda x, y: (x * y) % INF, range(1, r + 1))
    return (numer * pow(denom, INF - 2, INF)) % INF

A = sorted(A)
B = A[::]
n = A[-1]
temp = n // 2
min_ = 10 ** 9 + 7
for i in range(N - 1):
    A[i] -= temp
    A[i] = abs(A[i])
min_ = min(A)
ind = []
for i in range(N - 1):
    if A[i] == min_:
        if B[i] not in ind:
            ind.append(B[i])
            
mi = 0
ans = 0
for i in range(len(ind)):
    c = cmb(n, ind[i])
    if c > mi:
        mi = c
        ans = ind[i]
print(n, ans)

Submission status: Time Limit Exceeded

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

import math

maxcomb = 0
pair = 0

for i in range (0, N):
	z = math.comb(L[-1], L[i])
	if z > maxcomb:
		maxcomb = z
		pair = i

print(L[-1], L[pair])

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right
def comb(n, r):
    # if n - r < 0: return 0
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

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

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

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

    return result

def solve():
    N = II()
    A = LI()
    A = sorted(A)[::-1]

    a = A[0]
    cal = 0
    B = 0
    for i, b in enumerate(A[1:]):
        c = comb(a, b)
        if cal < c:
            B = b
            cal = c
    print(a, B)



if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
A.sort()
camel = A[-1]
bases = [camel // 2]
omega = set(A)
# print(omega)
while True:
    star = []
    for base in bases:
        # print(base)
        if base in omega:
            print(str(camel) + ' ' + str(base))
            exit()
        star.append(base + 1)
        star.append(base - 1)
    bases = star

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

maxA = max(A)
fact = [1]
for i in range(1, maxA+10):
    fact.append(fact[-1] * i % MOD)
def rev(x):
    return pow(x, MOD-2, MOD)
def cmb(i, k):
    if(i < k): return 0
    return fact[i] * rev(fact[k]) * rev(fact[i-k]) % MOD

if N == 2:
    print(A[1], A[0])
    exit()

# print(' A', A)
maxA = max(A)
ind = bisect_left(A, maxA//2)
res = 0
ress = A[ind]
st = max(0, ind-2)
en = min(N, ind+2)
# print(' A[st], A[en]', A[st], A[en-1])
for i in range(st, en):
    # print('  i', i)
    val = cmb(maxA, A[i])
    if res<val:
        res = val
        ress = A[i]
print(maxA, ress)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
from bisect import bisect
n=int(input())
lst=sorted(map(int,input().split()))
ans_max=0
m=lst[-1]
index=bisect(lst,m/2)
if 0<=index-1:
    tmp=factorial(m)//factorial(m-lst[index-1])//factorial(lst[index-1])
    if tmp>ans_max:
        ans_max=tmp
        ans=[m,lst[index-1]]
if m!=lst[index]:
    tmp=factorial(m)//factorial(m-lst[index])//factorial(lst[index])
    if tmp>ans_max:
        ans_max=tmp
        ans=[m,lst[index]]
print(" ".join(map(str,ans)))

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
from bisect import bisect
n=int(input())
lst=sorted(map(int,input().split()))
ans_max=0
for i in range(-1,-n,-1):
    index=bisect(lst,lst[i]/2)
    if 0<=index-1:
        tmp=factorial(lst[i])//factorial(lst[i]-lst[index-1])//factorial(lst[index-1])
        if tmp>ans_max:
            ans_max=tmp
            ans=[lst[i],lst[index-1]]
    if lst[i]!=lst[index]:
        tmp=factorial(lst[i])//factorial(lst[i]-lst[index])//factorial(lst[index])
        if tmp>ans_max:
            ans_max=tmp
            ans=[lst[i],lst[index]]
print(" ".join(map(str,ans)))