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

Solution (Python):
import numpy as np

n = int(input())
a = [int(x) for x in input().split()]
a_sorted = np.array(sorted(a))

a_sorted_floor = np.copy(a_sorted[:-1])
idx_floor = np.where(np.logical_and(a_sorted[-1] / 2 < a_sorted[:-1], a_sorted[:-1] < a_sorted[-1]))
a_sorted_floor[idx_floor] = a_sorted[-1] - a_sorted_floor[idx_floor]

print(a_sorted[-1], a_sorted[np.argmax(a_sorted_floor)])

Solution (Python):

N = int(input())
A = [int(i) for i in input().split()]

B = sorted(A)
pivot = B[-1] / 2.0
min_diff = B[-1]
min_index = None
for i, b in enumerate(B):
    diff = abs(b - pivot)
    if diff < min_diff:
        min_diff = diff
        min_index = i

print(B[-1], B[min_index])

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

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

Solution (Python):


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

sorted_a = sorted(a)

ai = sorted_a[n-1]

goal = ai / 2

min_dist = ai * 2
aj = ai

for i in range(n-1):
    dist = abs(sorted_a[i] - goal)
    if dist < min_dist:
        min_dist = dist
        aj = sorted_a[i]

print(ai, aj)

Solution (Python):
n=int(input())
lst=list(map(int,input().split()))
lst.sort()
x=lst[-1]
z=x/2
y=float('inf')
min_dif=100000000000
for w in lst:
    if abs(w-z)<min_dif:
        min_dif=abs(w-z)
        y=w
print(x,y)

Solution (Python):
from itertools import combinations

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

n = max(a)
s = n
r = n
d = n

for i, x in enumerate(a):
    if d >= abs(x - n / 2) and x != s:
        d = abs(x - n / 2)
        r = x

print(n)
print(r)

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

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

k=(enu)/2
sa=10000000000000000000000000000

for i in range(n-1):
    if abs(k-a[i])<sa:
        sa=k-a[i]
        aru=a[i]

print(enu,aru)

Solution (Python):
import bisect

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

v1=x[-1]
del x[-1]

ins = bisect.bisect_left(x,v1/2)

if len(x)<=1:
    v2=0
elif abs(x[ins]-v1/2) > abs(x[ins-1]-v1/2):
    v2=x[ins-1]
else:
    v2=x[ins]

print(v1,v2)

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

ai = max(A)
A.remove(ai)

aj = A[0]
delta_j = abs(ai/2 - aj)

for a in A:
    delta = abs(ai/2 - a)
    if delta < delta_j:
        aj = a
        delta_j = delta

print(ai, aj)

Solution (Python):
n = int(input())
a_list = list(map(int, input().split()))

ai = max(a_list)
a_list.remove(ai)
aj = int(sorted([a - (ai / 2) for a in a_list], key=abs)[0] + (ai / 2))

print(ai, aj)

Solution (Python):
n = int(input())
nums = list(map(int,input().split()))
nums.sort()
N = nums[-1]
work = 0
resind = 0
for i in range(n):
    if work < min((N-nums[i]),nums[i]):
        work = min((N-nums[i]),nums[i])
        resind = i
print(N,nums[resind])

Solution (Python):



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

A1 = max(a_s)
a_s.remove(A1)
A2 = a_s[0]
for a in a_s:
    if abs(A1 / 2 - A2) > abs(A1 / 2 - a):
        A2 = a

print(A1, A2)

Solution (Python):
def sel(data,n):
    an = n
    ans = 0
    for i in data:
        t = abs(n - i * 2)
        if t < an:
            an = t
            ans = i
    return(ans)

n = input()
As = list(map(int,input().split()))
As.sort()
l = As[-1]
m = sel(As[:-1],l)
print(l,m)

Solution (Python):
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
else:
    print a[1], a[0]

Solution (Python):
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]) and abs(bestr-a[kouho-1]) < abs(bestr-a[kouho+1]):
    ans_r = a[kouho-1]
elif abs(bestr-a[kouho]) < abs(bestr-a[kouho+1]):
    ans_r = a[kouho]
else:
    ans_r = a[kouho+1]
print(ans_n, ans_r)

Solution (Python):
n = int(raw_input())
a = map(int,raw_input().split())

a.sort()
m = max(a)
a.remove(m)

d = 99999999999
now = -1
if m%2 == 1:
  z = (m+1)/2
  for x in a:
    if d > abs(x - z):
      now = x
      d = abs(x - z)
  print m,now
else:
  z = m/2
  for x in a:
    if x<=z:
      if d > abs(z-x):
        now = x
        d = abs(x-z)
    else:
      if d > abs(x-z-1):
        now = x
        d = abs(x-z-1)
  print m,now

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

a=sorted(a)
b=max(a)
m=float('inf')
for i in a:
    if abs(b//2-i)<=abs(b//2-m) and i!=b:
        m=i
print(b,m)

Solution (Python):
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))

    l = max(a)
    r = 0
    best = l / 2
    for target in a:
        if abs(best - r) >= abs(best - target):
            r = target

    print(str(l) + " " + str(r))

Solution (Python):
n = int(input())
a_list = list(map(int, input().split()))

ai = max(a_list)
a_list.remove(ai)
sorted([a - (ai / 2) for a in a_list])[0]

tmp = ai
cand = ai
for x in [a - (ai / 2) for a in a_list]:
    if abs(x) < tmp:
        tmp = abs(x)
        cand = int(x + (ai / 2))

print(ai, cand)

Solution (Python):
n = int(input())
alst = list(map(int,input().split()))
alst.sort()
aj = alst[-1]
score = 10000000000
ai = -1
for i in range(n):
  s = abs(aj/2 - alst[i])
  if score > s:
    score = s
    ai = alst[i]
  else:
    print(aj,ai)
    break

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ai = max(a)
b = a[:]
for i in range(n):
    if a[i] != ai:
        b[i] = abs(a[i] - ai / 2)
    else:
        b[i] = abs(a[i] - ai / 2 + 1)
c = min(b)
d = b.index(c)
aj = a[d]
print(ai, aj)

Solution (Python):
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
    else:
        break
print(x, y)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
Ai = max(A)
x = float('inf')
for a in A:
    if abs((Ai - a) - a) <= x:
        x = abs((Ai - a) - a)
        Aj = a
print(Ai, Aj)

Solution (Python):
n = int(input())
lis = list(map(int,input().split()))
a = max(lis)
lis.remove(a)
ans = 100000000000
for i in range(n-1):
	if abs(a/2 - lis[i]) < ans:
		ans = abs(a/2 - lis[i])
		an = lis[i]
print(a,an)

Solution (Python):
import bisect
n=int(input())
a=[int(x) for x in input().split()]
y=sorted(a)
m=y[-1]
i = bisect.bisect_left(y,m/2.0)
if y[i]+y[i-1] >= m:
    print(str(m)+' '+str(y[i-1]))
else:
    print(str(m)+' '+str(y[i]))

Solution (Python):
n=int(raw_input())
a=[int(k) for k in raw_input().split(" ")]

mx=max(a)

best=-1
for k in a:
    if k!=mx and min(k,mx-k)>min(best,mx-best):
        best=k
print mx,best

Solution (Python):
input()
a=sorted(int(x)for x in input().split())
m=a[-1]
print(m,min(a,key=lambda x:abs(m-x*2)))