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:
n = int(input())
a = list(map(int,input().split()))
a_ = sorted(a)
if len(a)==2:
    print(a_[1],a_[0])
    exit()
a = a_[::-1]
import bisect
import math
def combinations_count(n,r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
ret = 0
for i in range(n//2):
    k = bisect.bisect_left(a_,a[i]//2)
    if a[i]//2-a_[k]>a_[k+1]-a[i]//2:
        k += 1
    cmb = combinations_count(a[i],a_[k])
    if ret<cmb:
        ans = [a[i],a_[k]]
        ret = cmb
print(ans[0],ans[1])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
a_ = sorted(a)
if len(a)==2:
    print(a_[1],a_[0])
    exit()
a = sorted(a)[::-1]
import bisect
import math
def combinations_count(n,r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
ret = 0
for i in range(n//2):
    k = bisect.bisect_left(a_,a[i]//2)
    kl = combinations_count(a[i],a_[k])
    kr = combinations_count(a[i],a_[k+1])
    if kl>kr:
        cmb = kl
        l = [a[i],a_[k]]
    else:
        cmb = kr
        l = [a[i],a_[k+1]]
    if ret<cmb:
        ans = l
        ret = cmb
print(ans[0],ans[1])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
a_ = sorted(a)
if len(a)==2:
    print(a_[1],a_[0])
    exit()
a = sorted(a)[::-1]
import bisect
import math
def combinations_count(n,r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
ret = 0
for i in range(n//2):
    kl = bisect.bisect_left(a_,a[i]//2)
    kr = bisect.bisect_right(a_,a[i]//2)
    cmb = max(combinations_count(a[i],a_[kl]),combinations_count(a[i],a_[kr]))
    if ret<cmb:
        ans = [a[i],a_[kr]]
        ret = cmb
print(ans[0],ans[1])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(item) for item in input().split()]
a.sort()

ai = a[-1]
aj = 1
for item in a[:-1]:
  diff = 1
  for i in range(item - aj):
    diff *= ai - aj - i
    diff /= item - i
  if diff < 1:
    break
  aj = item

print(ai, aj)

Submission status: Time Limit Exceeded

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

n=ri()
a=rl()
a.sort()
#nCr % MOD
def cmb(n, r, MOD=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])
            if MOD != 0:
                result %= MOD
 
    return result

import bisect
ans = []
for i in range(1,min(n,len(str(n))+3)):
    p = a[-i]
    p2 = p/2
    q_i = bisect.bisect_left(a,p2)
    if ((a[q_i]-p2) > (p2 - a[q_i-1])) or p==a[q_i] and q_i != 0:
        q_i -= 1
    q = a[q_i]
    ans.append([cmb(p,q),p,q])

ans.sort(key=lambda x:x[0],reverse=True)
print(*ans[0][1:])

Submission status: Time Limit Exceeded

Solution code:
import sys
from math import factorial

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


def f(A, a):
  if len(A) == 1:
    return A[0]
  
  if len(A) == 2:
    b1, b2 = A[0], A[1]
    if comb(a, b1) >= comb(a, b2):
      return b1
    else:
      return b2
  
  m = len(A) // 2
  b1, b2, b3 = A[m-1], A[m], A[m+1]
  c1, c2, c3 = comb(a, b1), comb(a, b2), comb(a, b3)
  c = max(c1, c2, c3)  
  
  if c2 == c:
    return b2
  elif c1 == c:
    return f(A[:m], a)
  else:
    return f(A[m+1:], a)


def main():
  input = sys.stdin.readline
  N = int(input())
  A = list(map(int, input().split()))
  A = sorted(A)
  ai = A[-1]
  A = A[:-1]
  aj = f(A, ai)
  print(ai, aj)


if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):

    if a[i] != max(a):
        
        b.append([abs((max(a)/2)-a[i]),i])

print('{} {}'.format(max(a),a[sorted(b)[0][1]]))

Submission status: Time Limit Exceeded

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

print(max(a),b[0][1])

Submission status: Time Limit Exceeded

Solution code:
import fileinput

factorials = [0, 1]


def factorial(n):
    global factorials
    if n >= len(factorials):
        for i in range(len(factorials)-1, n):
            factorials.append(factorials[i]*(i+1))
    return factorials[n]


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


def algorithm(n, a):
    sa = sorted(a, reverse=True)
    ma = sa[0]
    r = sa[n-1]
    for i in range(1, n-2):
        if ncr(ma, sa[i]) > ncr(ma, sa[i+1]):
            r = sa[i]
            break
    return "{} {}".format(sa[0], r)


def pass_inputs(input_lines):
    n = input_lines[0][0]
    a = input_lines[1]
    return algorithm(n, a)


def convert_int(s):
    try:
        r = int(s)
    except ValueError:
        r = s
    return r


def run():
    out = pass_inputs([[convert_int(v) for v in l.strip().split(" ")] for l in fileinput.input()])
    print(out)


if __name__ == "__main__":
    run()

Submission status: Time Limit Exceeded

Solution code:
import fileinput
from math import factorial


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


def algorithm(n, a):
    sa = sorted(a, reverse=True)
    ma = sa[0]
    r = sa[n-1]
    for i in range(1, n-2):
        if ncr(ma, sa[i]) > ncr(ma, sa[i+1]):
            r = sa[i]
            break
    return "{} {}".format(sa[0], r)


def pass_inputs(input_lines):
    n = input_lines[0][0]
    a = input_lines[1]
    return algorithm(n, a)


def convert_int(s):
    try:
        r = int(s)
    except ValueError:
        r = s
    return r


def run():
    out = pass_inputs([[convert_int(v) for v in l.strip().split(" ")] for l in fileinput.input()])
    print(out)


if __name__ == "__main__":
    run()

Submission status: Time Limit Exceeded

Solution code:
import fileinput
import operator
from functools import reduce


def factorial(n):
    return reduce(operator.mul, range(1, n+1), 1)


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


def algorithm(n, a):
    sa = sorted(a, reverse=True)
    ma = sa[0]
    r = sa[n-1]
    for i in range(1, n-2):
        if ncr(ma, sa[i]) > ncr(ma, sa[i+1]):
            r = sa[i]
            break
    return "{} {}".format(sa[0], r)


def pass_inputs(input_lines):
    n = input_lines[0][0]
    a = input_lines[1]
    return algorithm(n, a)


def convert_int(s):
    try:
        r = int(s)
    except ValueError:
        r = s
    return r


def run():
    out = pass_inputs([[convert_int(v) for v in l.strip().split(" ")] for l in fileinput.input()])
    print(out)


if __name__ == "__main__":
    run()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    if n == 2:
        print(a[0], a[1])
    ma = max(a)
    for i in range(n):
        if ma // 2 - i in a:
            print(ma, ma // 2 - i)
            exit()
        if ma // 2 - i + 1 in a:
            print(ma, ma // 2 - i + 1)
            exit()


main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    if n == 2:
        print(a[0], a[1])
    for i in range(n):
        if max(a) // 2 - i in a:
            print(max(a), max(a) // 2 - i)
            exit()
        if max(a) // 2 - i + 1 in a:
            print(max(a), max(a) // 2 - i + 1)
            exit()


main()

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left as bl
from math import factorial as f

def comb(a,b) :
    a,b = min(a,b),max(a,b)
    return f(b)//(f(a)*f(b-a))


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

p = L[-1]
q = bl(L,p/2)
#print(q)
if N == 2 :
    q = 0
    r = L[q]
else :
    if abs((p/2)-L[q]) < abs((p/2)-L[q-1]) :
        r = L[q]
    else :
        r = L[q-1]

ans = comb(p,r)
#print(ans)
print(p,r)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left as bl
from math import factorial as f

def comb(a,b) :
    a,b = min(a,b),max(a,b)
    return f(b)//(f(a)*f(b-a))


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

checker = 0
ans1 = 0
ans2 = 0
for i in range(1,N) :
    T = L[:i]
    t = bl(T,L[i]//2)
    if t >= 1 :
        if abs(L[i]/2 - L[t]) < abs(L[i]/2 - L[t-1]) :
            p = t
        else :
            p = t-1
    else :
        p = 0
    q = L[p]
    r = comb(L[i],q)
    #print(r)
    if checker < r :
        checker = r
        ans1 = L[i]
        ans2 = q
print(ans1,ans2)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial as f

N = int(input())
L = list(map(int,input().split()))
L = sorted(L,reverse=True)

def comb(a,b) :
    p = f(a)
    q = f(b)*f(a-b)
    return p//q

ANS = []
for i in range(N-1) :
    for j in range(i+1,N) :
        r = comb(L[i],L[j])
        ANS.append([r,L[i],L[j]])
ans = max(ANS)
print(ans[1],ans[2])

Submission status: Time Limit Exceeded

Solution code:
from math import factorial

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

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

result = {}
for i in range(n):
    for j in range(i+1, n):
        x = combo(a[j], a[i])
        s = ' '.join(map(str, [a[j], a[i]]))
        result[s] = x

print(max(result, key=result.get))

Submission status: Time Limit Exceeded

Solution code:
from math import factorial as fc
n = int(input())
x = list(map(int, input().split()))
x.sort()
a = x.pop()
k = 0
ans = 0
for i in range(n - 1):
    if k < (fc(a) // fc(x[i])) // fc(a - x[i]):
        ans = x[i]
        k = (fc(a) // fc(x[i])) // fc(a - x[i])
print(str(a)+" "+str(ans))

Submission status: Time Limit Exceeded

Solution code:
import math


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

A.sort()

frac = []

for k in range(A[-1]+1):
    if k == 0:
        frac.append(1)
    else:
        frac.append(frac[-1] * (k+1))

R = 0
M = []

if len(A) == 2:
    print(A[1], A[0])
else:
    for i in range(n):
        a = A[n-1-i]
        k = a / 2
        B = []
        C = []
        frac_a = frac[a]
        if R > frac_a // (frac[a-math.ceil(a/2)] ** 2):
            break
        for j in range(n):
            if A[j] < k:
                B.append(A[j])
            else:
                C.append(A[j])
                break
        b = B[-1]
        c = C[0]
        r_b = frac_a // (frac[a-b] * frac[b])
        r_c = frac_a // (frac[a-c] * frac[c])
        if r_b >= r_c and r_b > R:
            M = [a, b]
            R = r_b
        elif r_c >= r_b and r_c > R:
            M = [a, c]
            R = r_c

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

Submission status: Time Limit Exceeded

Solution code:
import math


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

A.sort()

R = 0
M = []

if len(A) == 2:
    print(A[1], A[0])
else:
    for i in range(n):
        a = A[n-1-i]
        k = a / 2
        B = []
        C = []
        frac_a = math.factorial(a)
        if R > frac_a // (math.factorial(a-math.ceil(a/2)) ** 2):
            break
        for j in range(n):
            if A[j] < k:
                B.append(A[j])
            else:
                C.append(A[j])
                break
        b = B[-1]
        c = C[0]
        r_b = frac_a // (math.factorial(a-b) * math.factorial(b))
        r_c = frac_a // (math.factorial(a-c) * math.factorial(c))
        if r_b >= r_c and r_b > R:
            M = [a, b]
            R = r_b
        elif r_c >= r_b and r_c > R:
            M = [a, c]
            R = r_c

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

Submission status: Time Limit Exceeded

Solution code:
import math


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

A.sort()

R = 0
M = []

if len(A) == 2:
    print(A[1], A[0])
else:
    for i in range(n):
        a = A[n-1-i]
        k = a / 2
        B = []
        C = []
        if R > math.factorial(a) // (math.factorial(a-math.ceil(a/2)) ** 2):
            break
        for j in range(n):
            if A[j] < k:
                B.append(A[j])
            else:
                C.append(A[j])
                break
        b = B[-1]
        c = C[0]
        r_b = math.factorial(a) // (math.factorial(a-b) * math.factorial(b))
        r_c = math.factorial(a) // (math.factorial(a-c) * math.factorial(c))
        if r_b >= r_c and r_b > R:
            M = [a, b]
            R = r_b
        elif r_c >= r_b and r_c > R:
            M = [a, c]
            R = r_c

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

Submission status: Time Limit Exceeded

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

max_a = max(A)

for i in reversed(range(max_a // 2 + 1)):
    # print(i)
    if(i in A):
        print(max_a, i)
        break
    elif((max_a - i) in A):
        print(max_a, max_a - i)
        break

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output


def chkprint(*args):
    names = {id(v): k for k, v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg), '???')+' = '+repr(arg) for arg in args))

# Binary converter


def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]

# --------------------------------------------


dp = None


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


def main():
    N = int(input())
    A = li_input()

    A.sort(reverse=True)
    ans_c = -1

    for i in range(10):
        n = A[i]

        if n == min(A):
            break

        half = n / 2
        diff = 10 ** 100

        A_ = A[:]
        A_.remove(n)

        for a in A_:
            if abs(a - half) < diff:
                r = a
                diff = abs(a - half)

        tmp_c = combinations_count(n, r)
        if tmp_c > ans_c:
            ans_c = tmp_c
            ans_n = n
            ans_r = r

    print(ans_n, ans_r)


main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output


def chkprint(*args):
    names = {id(v): k for k, v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg), '???')+' = '+repr(arg) for arg in args))

# Binary converter


def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]

# --------------------------------------------


dp = None


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


def main():
    N = int(input())
    A = li_input()

    A.sort(reverse=True)
    ans_c = -1

    for i in range(100):
        n = A[i]

        if n == min(A):
            break

        half = n / 2
        diff = 10 ** 100

        A_ = A[:]
        A_.remove(n)

        for a in A_:
            if abs(a - half) < diff:
                r = a
                diff = abs(a - half)

        tmp_c = combinations_count(n, r)
        if tmp_c > ans_c:
            ans_c = tmp_c
            ans_n = n
            ans_r = r

    print(ans_n, ans_r)


main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(map(int,input().split()))
s.sort()
c=0
if len(s)==2:
    ans=[max(s),min(s)]
for i in range(n//2,n):
    for j in s:
        if s[i]//2-2<=j<=s[i]//2+2:
            bunsi=bunbo=1
            for k in range(j):
                bunsi*=(s[i]-k)
                bunbo*=k+1
            if c<=bunsi//bunbo:
                c=bunsi//bunbo
                ans=[s[i],j]
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
import math
b=a.copy()
b=sorted(b,reverse=True)
comb_n=max(b)
b.pop(0)
c=b
def comb(n,r):
    return math.factorial(n)//((math.factorial(r))*(math.factorial(n-r)))
        
comb_list=[]
ind_list=[]
for i in c:
    comb_list.append(comb(comb_n,i))
    ind_list.append(i)
max_num=max(comb_list)
for i in range(len(comb_list)):
    if comb_list[i]==max_num:
        print(comb_n,ind_list[i])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
import math
comb_list=[]
ind_list=[]
def comb(n,r):
    return math.factorial(n)//((math.factorial(r))*(math.factorial(n-r)))
        
for idx in range(n):
    for jdx in range(idx+1,n):
        if a[idx]>a[jdx]:
            comb_list.append(comb(a[idx],a[jdx]))
            ind_list.append([a[idx],a[jdx]])
        else:
            comb_list.append(comb(a[jdx],a[idx]))
            ind_list.append([a[jdx],a[idx]])

max_num=max(comb_list)
for i in range(len(comb_list)):
    if comb_list[i]==max_num:
        ans=ind_list[i]
        
print(ans[0],ans[1])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
mx=0
alarge=a[n-1]
if a[0]>=alarge/2:
  asmall=0
  comb=1
  for i in range(1,asmall+1): comb*=(alarge-i+1)/i
else:
  j=0
  while a[j]<alarge/2:
    j+=1
  if alarge<=a[j-1]+a[j]:
    asmall=a[j-1]
  else:
    asmall=a[j]
  comb=1
  for i in range(1,asmall+1): comb*=(alarge-i+1)/i
print("{} {}".format(alarge,asmall))

Submission status: Time Limit Exceeded

Solution code:
from math import factorial

n = int(input())
a = list(map(int, input().split()))
a.sort()
max_a = max(a)
a.pop()
ans = -1
comb = 0
for a_i in a:
    if a_i >= max_a//2:
        comb = max(comb, (factorial(max_a) // factorial(max_a - a_i) * factorial(a_i)))
        ans = a_i
        break

for a_i in a[::-1]:
    if a_i <= max_a//2:
        if comb < factorial(max_a) // factorial(max_a - a_i) * factorial(a_i):
            ans = a_i
        break
print(max_a, ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
def getinputdata():

    # 配列初期化
    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])

arr = [int(x) for x in arr_data[1]]
    
maxdata=0
x=0
y=0
for v in list(itertools.combinations(arr, 2)):
    
    if v[0] <= v[1]:
        
        a = v[1]
        b = v[0]
        
    else:
        
        a = v[0]
        b = v[1]
        
    
    mysum1 = 1
    mysum2 = 1
    
    for i in range(a, a-b, -1):

        mysum1 *= i

    for i in range(b, 0, -1):

        mysum2 *= i

    
    if maxdata<=mysum1/mysum2:
        
        maxdata=mysum1/mysum2
        x=a
        y=b
        
    
print(x,y)

Submission status: Time Limit Exceeded

Solution code:
import scipy.misc as scm

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

now = 0
ans = [0] * 2
for i in range(n):
    for j in range(i + 1, n):
        new = scm.comb(a[j], a[i])
        if new > now:
            ans[0] = a[i]
            ans[1] = a[j]
            now = new
print(ans[1], ans[0])

Submission status: Time Limit Exceeded

Solution code:
import itertools
from scipy.misc import comb

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

ans = [0, 0]
max_comb = 0
combs = {}
for a_i, a_j in itertools.combinations(a, 2):
    if a_j > a_i:
        tmp = a_j
        a_j = a_i
        a_i = tmp

    if (a_i, a_i - a_j) in combs:
        continue

    c = comb(a_i, a_j, exact=True)
    combs[(a_i, a_j)] = c
    if c > max_comb:
        max_comb = c
        ans[0], ans[1] = a_i, a_j

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

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_sorted = sorted(a)
d = []
e = []
f = []
for i in range(n-1):
    b = a_sorted[i+1]
    for c in a_sorted:
        if c <  b:
            e.append(b)
            f.append(c)
            d.append(combinations_count(b,c))
g = d.index(max(d))
print('%d %d'%(e[g],f[g]))

Submission status: Time Limit Exceeded

Solution code:
def comb(n, k):
    m = 1
    if n < 2 * k:
        k = n - k
    for i in range(1, k + 1):
        m = m * (n - i + 1) / i    
    return m
n = int(input())
a = list(map(int, input().split()))
a_sorted = sorted(a)
d = []
e = []
f = []
for i in range(n-1):
    b = a_sorted[i+1]
    for c in a_sorted:
        if c <  b:
            e.append(b)
            f.append(c)
            d.append(comb(b,c))
g = d.index(max(d))
print('%d %d'%(e[g],f[g]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
sai = max(a)
ans = 0
def comb(b,c):
      d = 1
      kake = b
      while d < c:
           kake = kake * (b-d)
           d += 1
           kake = kake / d
      return kake
for i in range(N):
    ro = comb(sai,a[i])
    if ro > ans:
       ans = ro
       kore = a[i]
print(sai,kore)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
a = sorted(a)
sai = max(a)
ans = 0
def comb(b,c):
      d = 1
      kake = b
      while d < c:
           kake = kake * (b-d)
           d += 1
           kake = kake / d
      return kake
for i in range(N):
    ro = comb(sai,a[i])
    if ro > ans:
       ans = ro
       kore = a[i]
print(sai,kore)

Submission status: Time Limit Exceeded

Solution code:
num =int(input())
line = input()
line = line.rstrip().split(" ")
linei = []
for i in range(len(line)):
    linei.append(int(line[i]))
#print(max(linei))

for j in range(max(linei)):
    if linei.count(int(max(linei)/2)+j)>=1:
        if int(max(linei)/2)+j==max(linei):
            print(str(max(linei))+" 0")
            break
        else:
            print(str(max(linei))+" "+str(int(max(linei)/2)+j))
            break
    elif linei.count(int(max(linei)/2)-j)>=1:
        print(str(max(linei))+" "+str(int(max(linei)/2)-j))
        break
    else:
        j+=1

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
p = 10**5+1
mind = 10**10

for i in range(n):
    if a[i] == max(a):
        continue
    if abs(a[i] - max(a)/2) <= mind:
        mind = abs(a[i]-max(a)/2)
        p = i
        
print(max(a), a[p])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
number_list = list(map(int, input().split()))

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

max_value = 0
max_list_value = max(number_list)
reverse_sort_number_list = list(sorted(set(number_list)))

for j in range(len(reverse_sort_number_list)):
    combinations_count_value = \
        cmb(max_list_value, reverse_sort_number_list[j])
    if max_value < combinations_count_value:
        max_value = combinations_count_value
        value_pair = [max_list_value, reverse_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):
    if r == 0 or r == n: return 1
    if r == 1: return n
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

nCr = {}
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

max_value = 0
max_list_value = max(number_list)
reverse_sort_number_list = list(sorted(set(number_list)))

for j in range(len(reverse_sort_number_list)):
    combinations_count_value = \
        cmb(max_list_value, reverse_sort_number_list[j])
    if max_value < combinations_count_value:
        max_value = combinations_count_value
        value_pair = [max_list_value, reverse_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):
    if r == 0 or r == n: return 1
    if r == 1: return n
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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)] = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    return nCr[(n,r)]

max_value = 0
max_list_value = max(number_list)
reverse_sort_number_list = list(sorted(set(number_list)))

for j in range(len(reverse_sort_number_list)):
    combinations_count_value = \
        cmb(max_list_value, reverse_sort_number_list[j])
    if max_value < combinations_count_value:
        max_value = combinations_count_value
        value_pair = [max_list_value, reverse_sort_number_list[j]]

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import math
import scipy.misc as scm

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
max_list_value = max(number_list)
reverse_sort_number_list = list(sorted(set(number_list)))

for j in range(len(reverse_sort_number_list)):
    combinations_count_value = scm.comb(max_list_value, reverse_sort_number_list[j])
    if max_value < combinations_count_value:
        max_value = combinations_count_value
        value_pair = [max_list_value, reverse_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
max_list_value = max(number_list)
reverse_sort_number_list = list(sorted(set(number_list)))

for j in range(len(reverse_sort_number_list)):
    combinations_count_value = \
        combinations_count(max_list_value, reverse_sort_number_list[j])
    if max_value < combinations_count_value:
        max_value = combinations_count_value
        value_pair = [max_list_value, reverse_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
sort_number_list = list(sorted(set(number_list), reverse=True))
reverse_sort_number_list = list(sorted(set(number_list)))
dp = [[0 for i in range(max(sort_number_list) + 1)] for j in range(max(sort_number_list) + 1)]

for i in range(len(sort_number_list)):
    for j in range(len(sort_number_list)):
        if reverse_sort_number_list[j] >= sort_number_list[i]:
            break
        if sort_number_list[i] > reverse_sort_number_list[j]:
            if dp[sort_number_list[i]][reverse_sort_number_list[j]] == 0:
                dp[sort_number_list[i]][reverse_sort_number_list[j]] = \
                    combinations_count(sort_number_list[i], reverse_sort_number_list[j])
            if max_value < dp[sort_number_list[i]][reverse_sort_number_list[j]]:
                max_value = dp[sort_number_list[i]][reverse_sort_number_list[j]]
                value_pair = [sort_number_list[i], reverse_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
sort_number_list = list(sorted(set(number_list), reverse=True))
dp = [[0 for i in range(max(sort_number_list) + 1)] for j in range(max(sort_number_list) + 1)]

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]:
            if dp[sort_number_list[i]][sort_number_list[j]] == 0:
                dp[sort_number_list[i]][sort_number_list[j]] = combinations_count(sort_number_list[i], sort_number_list[j])
            if max_value < dp[sort_number_list[i]][sort_number_list[j]]:
                max_value = dp[sort_number_list[i]][sort_number_list[j]]
                value_pair = [sort_number_list[i], sort_number_list[j]]

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