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

Solution code:
N=int(input())
A=list(map(int,input().split()))
A1=max(A)
A2=(-1)
for i in range(N):
    if A[i]==A1:
        pass
    elif abs(A1/2-A[i])<abs(A1/2-A2):
        A2=A[i]
print(A1,A2)

Submission status: Accepted

Solution code:
input()
a=list(map(int,input().split()))
m=max(a)
d=min(a,key=lambda d:abs(m-2*d)if m!=d else 1e18)
print(m,d)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
ai = max(a)
aj = min(a)
for j in a:
    if abs(ai - 2 * aj) > abs(ai - 2 * j):
        aj = j
print(ai, aj)

Submission status: Accepted

Solution code:
def getN():
    return int(input())


def getNM():
    return map(int, input().split())


def getList():
    return list(map(int, input().split()))

n = getN()
nums = getList()

c1 = max(nums)
nums.sort()
nums = nums[:-1]

c2 = 0
dif = float(c1)/2

for num in nums:
     diff = abs(float(c1)/2 - float(num))
     if diff < dif:
         dif = diff
         c2 = num

print(c1, c2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
a.sort()
x = a[-1]
y = max(a[: -1], key=lambda a_i: min(a_i, a[-1] - a_i))
print(x, y)

Submission status: Accepted

Solution code:
'''input
2
100 0
'''
n = input()
arr = map(int,raw_input().split())
m = max(arr)
zz = float(m)/2
diff = 10**20
arr.sort()
for i in range(n):
	if abs(arr[i]-zz) < diff:
		diff = abs(arr[i]-zz)
		ans = arr[i]
print m,ans

Submission status: Accepted

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

y = max(x)
sub = y
res = 0
for i in range(n):
    if abs(float(y/2-x[i])) < sub and x[i] != y:
        sub = abs(float(y/2-x[i]))
        res = x[i]

print(y,res)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
m = max(a)
r = 0
for i in a:
    if abs(m//2-i)<abs(m//2-r):
        r = i
print(m,r)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans1=max(a)
a.remove(ans1)
ans2=min(a,key=lambda b:abs(ans1/2-b))
print(ans1,ans2)

Submission status: Accepted

Solution code:
import math

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

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


a.sort(reverse=True)
n=a[0]
r=a[N-1]

for i in range(1,N):
  if abs(r-n/2)>abs(a[i]-n/2):
    r=a[i]
print(n,r)

Submission status: Accepted

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

    x, y = max(a), min(a)
    for i in range(n):
        if abs(a[i]-x/2) < abs(y-x/2):
            y = a[i]

    print(x, y)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect

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

med = a_list[-1] / 2
idx = bisect.bisect_left(a_list, med)

if (med - a_list[idx-1]) > (a_list[idx] - med):
    print('%d %d' % (a_list[-1], a_list[idx]))
else:
    print('%d %d' % (a_list[-1], a_list[idx-1]))

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import *

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

n = read()
a = sorted(reads())

x = a.pop()
y = sorted((abs(x-2*p), p) for p in a)[0][1]
print(x, y)

Submission status: Accepted

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

l = max(a)
r = 0
d = 10**9
for i in range(n):
    if (l == a[i]):
        continue
    tmp = abs(l - 2*a[i])
    if (tmp < d):
        r = a[i]
        d = tmp

print("{0} {1}".format(l, r))

Submission status: Accepted

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

def dist(x, y):
    assert 0 <= y <= x
    return min(y, x - y)

def main():
    n = int(input())
    ai = list(map(int, input().split()))
    ai = sorted(ai)

    x = ai[-1]
    y = ai[0]
    for i in range(n - 1):
        if dist(x, ai[i]) > dist(x, y):
            y = ai[i]

    print("%d %d" % (x, y))

main()

Submission status: Accepted

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

l=a[-1]
r=a[0]
for num in a:
    if abs(num-l/2)<abs(r-l/2):
        r=num
print(str(l)+" "+str(r))

Submission status: Accepted

Solution code:
# coding: utf-8
import sys


# 標準入力
n = int(sys.stdin.readline().strip())
aArray = list(map(int, sys.stdin.readline().strip().split(" ")))


# aArrayから最大となるコンビネーションの組を探し出す
sortedArray = sorted(aArray)
maxNum = max(aArray)
idealHalfNum = maxNum / 2

i = 0
while abs(idealHalfNum - sortedArray[i]) > abs(idealHalfNum - sortedArray[i+1]):
    i = i + 1

# 標準出力
print(maxNum, sortedArray[i])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans1 = a[n - 1]
ans2 = a[0]
for i in range(n):
    ans2 = max(ans2, min(a[i], ans1 - a[i]))
exist = False
for i in range(n):
    if (ans2 == a[i]):
        exist = True
if (exist):
    print(ans1, ans2)
else:
    print(ans1, ans1 - ans2)

Submission status: Accepted

Solution code:
input()
da = list(map(int,input().split()))
 
x = max(da)
y = x + 1
for i in da:
  if i == x:
    continue
  if abs(x/2 - i ) <= abs(x/2 - y):
    y = i
print(x,y)

Submission status: Accepted

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

x = max(a)
y = x + 1
for e in a:
	if x == e:
		continue
	if abs(x / 2 - e) < abs(x / 2 - y):
		y = e

print(x, y)

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
A=sorted([int(i) for i in input().split()])
ai=max(A)
j=np.argmin(np.array([abs(a-ai/2) for a in A[:n-1]]))
aj=A[j]
print(str(ai)+" "+str(aj))

Submission status: Accepted

Solution code:
import numpy as np

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

ai = a[-1]
a = a[:-1]
aj = a[np.argmin(np.abs(a - ai/2))]

print(ai, aj)

Submission status: Accepted

Solution code:
import bisect as bs
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
max = a[len(a)-1]
idx  = bs.bisect_left(a,int(max/2))
if idx != 0:
    idx = idx-1 if max/2.0-a[idx-1] <= a[idx]-max/2.0 else idx
print(max,a[idx])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ai = max(a)
ai2 = ai/2
aj = a[1] if a[0] == ai else a[0]
d = abs(aj - ai2)
for i in range(1,n):
    tempd = abs(a[i] - ai2)
    if tempd < d and a[i] != ai:
        d = tempd
        aj = a[i]

print(ai, aj)

Submission status: Accepted

Solution code:
n = int(input())
A = [int(i) for i in input().split(" ")]
A.sort()
k = A[-1]
x = 0
for i in range(n-1):
    if abs(k/2-A[x])>abs(k/2-A[i]):
        x = i
print(k, A[x])

Submission status: Accepted

Solution code:

import numpy as np
import math

def get_nearest_val(l, n):
    i = np.abs(np.asarray(l) - n).argmin()
    return l[i]

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

max_n = max(A)
A = sorted(A)
max_n = A[-1]
# A = A.pop
A.pop(-1)
key_r = (max_n + 1) / 2
# key_r = int((max_n + 1) / 2)
# print(key_r)

# left_r = get_nearest_val(A, key_r, side='left')
# # print(left_r)
# right_r = get_nearest_val(A, key_r, side='right')
# # print(right_r)

# left_comb = comb(max_n, left_r)
# # print(left_comb)
# right_comb = comb(max_n, right_r)
# # print(right_comb)

# if left_comb >= right_comb:
#     print(str(max_n) + ' ' + str(left_r))
# else:
#     print(str(max_n) + ' ' + str(right_r))

r = get_nearest_val(A, key_r)
# r = get_nearest_val(A[:len(A)-1], key_r)
print(str(max_n) + ' ' + str(r))

Submission status: Accepted

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

import bisect
m = a[-1] / 2
b = bisect.bisect_left(a, m)
if abs(a[b]-m) < abs(a[b-1]-m):
  res = a[b]
else:
  res = a[b-1]

print(a[-1], res)

Submission status: Accepted

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

ai = max(a)
m = ai/2

aj = -1
for ak in a:
    if ak != ai and abs(ak - m) < abs(aj - m):
        aj = ak
print("{} {}".format(ai, aj))

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())

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

a.sort()

a_max = a[N - 1]

ave = a_max / 2


dif = 1000000000
difidx = -1
difidx2 = -1
p = 1
s = 1


for i in range(N):
    an = abs(a[i] - ave)
    if dif > an:
        dif = an
        difidx = i
    elif dif == an:
        difidx2 = i

ans = a[difidx2] if difidx2 > 0 else a[difidx]
ans2 = str(a_max)
if N > 3:
    print(str(a_max) + " " + str(ans))
else:
    if a[0] > a[1]:
        print(str(a[0]) + " " + str(a[1]))
    else:
        print(str(a[1]) + " " + str(a[0]))

Submission status: Accepted

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

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

    return result

# Nを取得
n = int(input())

# Aiを取得
a_list = list(map(int, input().split()))

# 昇順にソートしたAiを取得
a_sorted = sorted(a_list)

# 最大値およびその1/2の値を取得
a_max = max(a_sorted)

# comb(n,r)が最大になるrを取得
r = 0
d_min = a_max + 1
for a in a_sorted:
    d = abs(a_max - (2 * a))
    if d < d_min:
        d_min = d
        r = a
    else:
        break

# c = comb(a_max, r)

# 結果を出力
print("{} {}".format(a_max, r))

Submission status: Accepted

Solution code:
n = int(input())

a = input().split()

a = [int(x) for x in a]

am = max(a)
ai = 0
r = abs(a[0] - (am/2)) 

for i in range(n):
    if r >= abs(a[i]-(am/2)):
        r = abs(a[i]-(am/2))
        ai = a[i]
        
print("{0} {1}".format(am,ai))

Submission status: Accepted

Solution code:
import numpy as np


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


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

ans1 = max(a)  # 出力1
if n == 2:
    ans2 = min(a)
else:
    ans2 = nearestValue(a, ans1/2)

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

Submission status: Accepted

Solution code:
import numpy as np

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

a_max = max(a)
a_max_index = np.argmax(a)

del a[a_max_index]

center = a_max / 2

a_x_index = np.argmin(np.absolute(np.array(a) - center))
a_x = a[a_x_index]

print(str(a_max) + ' ' + str(a_x))

Submission status: Accepted

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

b = max(a)
c = 1 << 10
for i in a:
    if abs(b // 2 - c) > abs(b // 2 - i) and i != b:
        c = i

print("{} {}".format(b, c))

Submission status: Accepted

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

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

median = sorted_l[m]
if (m + 1 < n and (abs(sorted_l[m + 1] - med) < abs(median - med))):
    median = sorted_l[m + 1]

if (0 < m - 1 and (abs(sorted_l[m - 1] - med) < abs(median - med))):
    median = sorted_l[m - 1]

if n == 2:
    print(max_, sorted_l[0])
else:
    print(max_, median)

Submission status: Accepted

Solution code:
import math

n = int(input())
a = [int(x) for x in input().split()]
a.sort()
x = max(a)
a.remove(x)
maxi = 0
mind = x
for i in range(len(a)):
    d = abs((x+1) // 2 - a[i])
    if d < mind:
        maxi = i
        mind = d
print(str(x) + ' ' + str(a[maxi]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = LI()
    t = max(a)
    m = -1
    r = -1
    for c in a:
        if min(c,t-c) > m and c != t:
            r = c
            m = min(c,t-c)

    return '{} {}'.format(t,r)


print(main())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n = input()
n= int(n)
ls = input().split()
lsnum = list(map(int,ls))
ma = max(lsnum)

minvalue = 10000000000
ans = -1
for num in lsnum:
    if num == ma:
        continue
    value = abs(ma-num*2)
    if minvalue >= value:
        minvalue = value
        ans = [ma, num]
print (ans[0], ans[1])

Submission status: Accepted

Solution code:
#!/usr/bin/env python
N = int(input())
A = sorted(map(int, input().split()))

n = A[-1]
r = sorted(A[:-1], key=lambda x: abs(x-n/2))[0]
print(n, r)

Submission status: Accepted

Solution code:
count = int(input())
li = list(map(int, input().split()))

sli = sorted(li)

pair_a = sli[len(sli) - 1]
pair_b = 0
current_max = 0

i = sli[len(sli) - 1]

diff = 10**9
for j in range(0, len(sli) - 1):
    h = pair_a / 2
    if abs(h - sli[j]) < diff:
        diff = abs(h - sli[j])
        pair_b = sli[j]

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

Submission status: Accepted

Solution code:
from bisect import bisect

n = int(input())

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

a = A[-1]

i = bisect(A,a/2)
j = max(i-1,0)

k = min((A[i]-a/2, i),(a/2-A[j],j))[1]

print(a,A[k])

Submission status: Accepted

Solution code:
N = int(input())
src = list(map(int,input().split()))
n = max(src)

d = n+1
r = min(src)
for a in src:
    if a == n: continue
    if abs(n - a*2) < d:
        d = abs(n - a*2)
        r = a
print(n, r)

Submission status: Accepted

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

def find_p(n, i):
    lo = 0
    hi = i
    mid = (hi-lo)//2
    xl = a[0]
    xh = a[i]
    while hi - lo > 1:
        mid = (hi+lo)//2
        if a[mid] > n//2:
            hi = mid
        else:
            lo = mid
    if abs(a[lo] - n/2) > abs(a[hi] - n/2):
        return a[hi]
    else:
        return a[lo]



print(str(a[-1]) + ' ' + str(find_p(a[-1], N-1)))

Submission status: Accepted

Solution code:
import bisect

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

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

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

print(maxA, As[i])

Submission status: Accepted

Solution code:
import numpy as np
import itertools

N = int(raw_input())
A = map(int, raw_input().split())

def mul(x, y):
    return x * y

def nCr(n, r):
    print n, r
    if r == 0:
        return 1
    if n/2 < r:
        return nCr(n, n-r)
    print range(n, n - r, -1), range(1, r+1)
    return np.prod(range(n, n - r, -1)) / np.prod(range(1, r+1))

def nCrMax(n):
    return nCr(n, n/2)

sortedA = sorted(A, reverse = True)

max = -1
for i in range(N - 1):
    n = sortedA[i]
    target = n/2
    newA = sortedA[:i] + sortedA[i+1:]
    r = newA[np.argmin(map(lambda x: abs(x - target), newA))]
    #ncr = nCr(n, r)
    #if(nCr > max):
    #    max = nCr
    #else:
    #    break
    #if nCrMax(sortedA[i+1]) < max:
    #    break
    break
    
print n, r

Submission status: Accepted

Solution code:
import numpy as np

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

M = np.max(n_list)
mid_M = M / 2
ex_M_list = list(n_list)
ex_M_list.remove(M)

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

print(M, ex_M_list[a])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
import bisect
from scipy.misc import comb
 
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
b = a.pop()
ind = bisect.bisect_left(a, b/2)

if ind == n-1:
    c = a.pop()
elif ind == 0:
    c = a[0]
else:
    if b/2 - a[ind-1] < a[ind] - b/2:
        c = a[ind-1]
    else:
        c = a[ind]

print(b, c)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import bisect


def get_closest(nums, target):
    pos = bisect.bisect_left(nums, target)
    if pos == 0:
        return nums[0]
    if pos == len(nums):
        return nums[-1]

    before = nums[pos - 1]
    after = nums[pos]

    if target in [before, after]:
        return target

    if after - target < target - before:
        return after
    else:
        return before


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

nums = sorted(nums)
top = nums[-1]
nums.remove(top)

if top % 2 == 0:
    optimal = top / 2
    bottom = get_closest(nums, optimal)
else:
    res1 = get_closest(nums, top / 2)
    res2 = get_closest(nums, (top + 1) / 2)

    if abs(res1 - (top/2)) < abs(res2 - ((top + 1) / 2)):
        bottom = res1
    else:
        bottom = res2

print "{} {}".format(top, bottom)

Submission status: Accepted

Solution code:
f = lambda :[int(i) for i in input().split()]
from sys import stderr
f = lambda :[int(i) for i in input().split()]
from functools import reduce
from operator import add
debug = lambda *x:stderr.write(reduce(add,repr(x))+'\n')

num = int(input())
a = f()
a.sort()
# Pascalの三角形を思うと、nは大きく、rはn/2に近いほうがいい
n = a[-1]
half = int(n/2)
r = a[0]
for po in a:
    if abs(half - po) < abs(half - r) or (r == half - 1 and po == r + 2):
        r = po
print(n,r)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Contents   : AtCoder Regular Contest 095 d問題
Author     : Kitaura Hiromi
LastUpdate : 20180414
Since      : 20180414
"""

# c(m, n) = (m+n)!/m!n!
# mが同じな場合、nはmの半分なら最大
# mが大きいほどc(m, n)は大きい

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

max_a = max(a)
tmp = 0
for i in range(n):
    if abs(max_a / 2 - tmp) > abs(max_a / 2 - a[i]):
        tmp = a[i]
print(max_a, tmp)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
A = list(map(int, input().split()))

sa = np.sort(A)
max_num = sa[-1]
sa = sa[:-1]

min_num = sa[np.abs(sa-((max_num+1)//2)).argmin()]
print(max_num, min_num)

Submission status: Accepted

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

import copy

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

ai = max(a)
a_new = copy.copy(a)

a_new.remove(ai)

aj = a_new[0]
ai_half = ai/2
for i in range(n-1):
    if abs(a_new[i] - ai_half) < abs(aj - ai_half):
        aj = a_new[i]

print ai,aj

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
M = max(a)
a.remove(M)
for i in range(n - 1):
    if a[i] > M / 2:
        if a[i] - M / 2 <= M / 2 - a[i - 1]:
            print(M, a[i])
            break
        else:
            print(M, a[i - 1])
            break
else:
    print(M, a[-1])

Submission status: Accepted

Solution code:
def main():
    N = int(input())

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

    n = max(A)
    A.remove(n)

    tmp = []
    for a in A:
        # print(
        #     n,
        #     a,
        #     n - a, )
        tmp.append((max(a, n - a), a))
    print(n, min(tmp)[1])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

a1 = max(p)
a2 = min(p)
half = (a1+1) // 2
s = n // 2
graph = [0] * n

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

Submission status: Accepted

Solution code:
import numpy as np


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

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

n = int(input())
a = list(map(int, input().split()))
a.sort()
max = max(a)
min = getNearestValue(a,max/2)

if max == min:
    print(max, getNearestValue(a[:n-1], max / 2))
else:
    print(max,getNearestValue(a,max/2))

Submission status: Accepted

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

maxv = max(arr)
half = maxv/2
mindelta = float('inf')
ans = None
for i in range(N):
  if arr[i] == maxv:
    continue
  delta = abs(arr[i] - half)
  if delta < mindelta:
    mindelta = delta
    ans = arr[i]
print(maxv, ans)

Submission status: Accepted

Solution code:
from bisect import *

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

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

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

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

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

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

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

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

Submission status: Accepted

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

ans1 = max(a)
a.remove(ans1)
key = ans1
m = 0
for i in range(n - 1):
    if abs(a[i] - ans1 // 2) < key:
        key = abs(a[i] - ans1 // 2)
        m = i

print(ans1,end=" ")
print(a[m])

Submission status: Accepted

Solution code:
import sys
from collections import Counter
import random
import numpy as np

def fact(n):
    x=1
    for i in range(2,n+1):x*=i
    return x

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

n=int(input())
a=list(map(int,input().split()))
a.sort()
z=a.pop(n-1)
#b=[a[i]/2 for i in range(n-1)]
min=10**10
y=z/2
x=0
for i in range(n-1):
    dif=abs(y-a[i])
    if(dif<min):
        min=dif
        x=a[i]
print(z,x)

Submission status: Accepted

Solution code:
import math

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

a.sort()

ai = a[n-1]
mid = ai/2
diff = ai
aj = 0

for i in range(n-1):
    if abs(a[i] - mid) < diff:
        aj = a[i]
        diff = abs(a[i]-mid)

print(ai,aj)

Submission status: Accepted

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
a=i2()
x=max(a)
y=float("inf")
for i in range(n):
 if x!=a[i] and abs(y-x//2)>abs(a[i]-x//2):
    y=a[i]
print(x,y)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split(' '))))

i = A.argmax()
j = 0
if i == 0:
    j = 1

for n in range(1, N):
    if j == i:
        continue

    if abs(A[i]/2 - A[n]) < abs(A[i]/2 - A[j]):
        j = n

print(A[i], A[j])

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from math import *

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

n = A[-1]

score_max = 0
r = A[0]
for i in range(1, N-1):
    score = min(A[i], n-A[i])
    if score_max < score:
        score_max = score
        r = A[i]
    else:
        break

print(n, r)

Submission status: Accepted

Solution code:

def main():
    input()
    xx = list(map(int, input().split()))
    xx.sort()
    a = xx.pop()
    b = max(xx, key=lambda x: min(x, a - x))
    print(a, b)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())

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

a=max(nums)

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

b=nums[diffs.index(min_diff)]

print(a,b)

Submission status: Accepted

Solution code:
input()
aa = sorted(list(map(int, input().split())))
n = aa[-1]
r = aa[0]
d = abs(n-2*r)
for a in aa[:-1]:
    td = abs(n-2*a)
    if td < d:
        r = a
        d = td
print(n, r)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())))
a1 = a[n-1]
b = sorted([(abs(a[i] - a1/2),a[i], i) for i in range(n)])
a2 = a[b[0][2]]
print(a1, a2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from bisect import bisect, bisect_left 
def inpl(): return list(map(int, input().split()))

N = int(input())
A = sorted(inpl())

n = A[-1]

l = A[max(bisect(A, n/2)-1, 0)]
r = A[bisect_left(A, n/2)]

if abs(n/2-l) < abs(r-n/2) or r==n:
    print(n, l)
else:
    print(n, r)

Submission status: Accepted

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

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

a=sorted(C)

M=a[-1]


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

Submission status: Accepted

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

a = list(sorted(a))
j = 0
for i in range(1, n - 1):
    if abs(a[-1] - 2 * a[i]) < abs(a[-1] - 2 * a[j]):
        j = i
print("%d %d" % (a[-1], a[j]))

Submission status: Accepted

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

def p(n):
    x = 1
    for i in range(1, n + 1):
        x *= i
    return x

def comb(n, r):
    return p(n) // p(n - r) // p(r)

xs = sorted(A)

m1 = xs[-1]
m0 = m1 / 2

ys = sorted(xs, key=lambda x:abs(x-m0))
print(m1, ys[0])

Submission status: Accepted

Solution code:
n=int(input())
a=sorted([int(i) for i in input().split()])
N=a[n-1]
Kindex=0
K=a[Kindex]
M=10**9
for i in range(n-2):
    if abs(2*a[i]-N)<=M:
        Kindex=i
        M=abs(2*a[i]-N)
print(N,a[Kindex])

Submission status: Accepted

Solution code:
n=int(raw_input())
a=map(int,raw_input().split())
a.sort()
s=a[0]
from math import fabs
for i in range(n-1):
	if fabs(a[n-1]/2.0-a[i])<fabs(a[n-1]/2.0-s):
		s=a[i]
print a[n-1],s

Submission status: Accepted

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n = f.read_int()
    a = f.read_int_list()

    i = max(a)
    a.remove(i)
    j = sorted(a, key=lambda x: abs(x*2-i))[0]

    return "%d %d"%(i,j)


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
y = a[-1]
m = None
x = None
for i in range(n - 1):
    k = a[i]
    l = max(k, y - k)
    if m is None or m > l:
        m = l
        x = k
print(y, x)

Submission status: Accepted

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

a.sort()
large = a.pop()

min_val =  0
for i in a:
    min_val =  max(min_val, min(i,large-i)
                   )

if min_val in a:
    print(large , min_val)
else:
    print(large, large-min_val)

Submission status: Accepted

Solution code:
import bisect

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