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 = tuple(int(x) for x in input().split())

def hoge(n, r):
 return n * (min(n-r, r))

n = max(a)
ans = (n, a[0]) if n != a[0] else (n, a[1])
for i in a:
 if n == i: continue
 ans = (n, i) if hoge(*ans) < hoge(n, i) else ans
print(*ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
# k_C_r
k =  a[0]
d_min = float('inf')
for i in range(1,n):
    d = abs(a[i] - k/2)
    if d < d_min:
        d_min = d
        r = a[i]

print(k,r)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    if n == 2:
        print(max(a), min(a))
    else:
        ma = max(a)
        sa = sorted([(i, abs(ma // 2 - a[i]))
                     for i in range(n)], key=lambda x: x[1])
        print(ma, a[sa[0][0]])


main()

Submission status: Accepted

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

m = a[-1]

r = 10**10
for i in range(n):
    if abs(a[i]-(m-a[i])) < r:
        r = abs(a[i]-(m-a[i]))
        idx = i

print(m, a[idx])

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
m = a[-1]
print(m, min(a, key=lambda x:abs(m-x-x)))

Submission status: Accepted

Solution code:
from bisect import bisect_left
n = int(input())
a = sorted(list(map(int, input().split())))
if n == 2:
    print(a[1], a[0])
    exit()
m = a.pop()
idx = bisect_left(a, m//2)
if idx == 0:
    print(m, a[0])
    exit()
else: 
    r1 = a[idx-1]
    r2 = a[idx]

    if r1 > m-r2:
        r = r1
    else:
        r = r2

print(m, r)

Submission status: Accepted

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

a.sort()
x = a.pop()
hx = x / 2

ma = a.pop()
for i in a:
  if abs(hx - i) < abs(hx - ma):
    ma = i
    
print(x, ma)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())))
y = A.pop(-1)
print(y, min(A, key=lambda x: abs(y - 2 * x)))

Submission status: Accepted

Solution code:
def check(a, b, target):
    if abs(target - a) < abs(target - b):
        return a
    else:
        return b


n, a = int(input()), list(map(int, input().split()))
if n == 2:
    a.sort(reverse = True)
    print(a[0], a[1])
    exit()
a.sort()
l, r = 0, n
target = a[-1] >> 1
while l < r:
    mid = (l + r) >> 1
    if a[mid] > target:
        r = mid
    else:
        l = mid + 1
if a[l] <= target:  # check a[l] and a[l + 1]
    print(a[-1], check(a[l], a[l + 1], target))
else:  # check a[l] and [l - 1]
    print(a[-1], check(a[l - 1], a[l], target))

Submission status: Accepted

Solution code:
n = int(input())
a = list(int(i) for i in input().split())
ans1 = max(a)
tmp1 = ans1/2
ans2 = 10**11
if len(set(a)) > 2:
 for i in a:
  ans2 = min(ans2,abs(tmp1-i))
 if  int(tmp1+ans2) in a:
  ans3 = tmp1+ans2
 else:
  ans3 = tmp1-ans2
 print(ans1,int(ans3))
else:
  a.remove(ans1)
  print(ans1,min(a))

Submission status: Accepted

Solution code:
def near_num(x,nodes):
    temp = []
    for i in range(len(nodes)):
        temp.append(abs(x-nodes[i]))
        if i != 0:
            if temp[i] >= temp[i-1]:
                return nodes[i-1]
    else:
        return nodes[len(nodes)-1]
        

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

M = s[N-1]

if M % 2 == 0:
    m = near_num(M//2,s)
elif abs(near_num(M//2+1,s)-(M//2+1)) >= abs(near_num(M//2,s)-M//2):
    m = near_num(M//2,s)
else:
    m = near_num(M//2+1,s)

print(M,m)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
maximum = max(l)
a = 10 ** 10
r = (maximum - 1) / 2

for x in l:
    if abs(x-r) <= a:
        a = abs(x-r)
        tmp = x
print(maximum,tmp)

Submission status: Accepted

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

maxA = max(A)
half = maxA/2
diff = 10**10
ans = 0
for i in range(N):
    if A[i] != maxA and abs(A[i]-half) < diff:
        diff = abs(A[i]-half)
        ans = A[i]

print(maxA, ans)

Submission status: Accepted

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

sort_a = sorted(a,reverse=True)
max_a = sort_a[0]

ans=0
for i in range(n):
  if min(abs(max_a/2-sort_a[i]),abs(max_a/2-ans)) == abs(max_a/2-sort_a[i]):
    ans = sort_a[i]
print(max_a,ans)

Submission status: Accepted

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

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

    a.sort()
    i = bisect.bisect_left(a, a[n - 1] / 2)

    r = 0
    if a[i] * 2 == a[n - 1]:
        r = a[i]
    elif i == 0:
        r = a[0]
    elif i == n - 1:
        r = a[i - 1]
    elif a[n - 1] - a[i - 1] * 2 < a[i] * 2 - a[n - 1]:
        r = a[i - 1]
    else:
        r = a[i]

    print('{} {}'.format(a[n - 1], r))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
s=list(map(int,input().split()))
s.sort()
a=s[-1]
ans=float('inf')
for i in s:
    if i==a:
        continue
    if ans>=abs(i-a//2):
        ans=abs(i-a//2)
        k=i
print(a,k)

Submission status: Accepted

Solution code:
import bisect

n=int(input())
s=list(map(int,input().split()))
s.sort()
a=s[-1]
index=bisect.bisect_left(s,a//2)
diff1=abs(a//2-s[index-1])
diff2=abs(a//2-s[index])
if diff1>=diff2:
    k=s[index]
else:
    k=s[index-1]
if a==k:
    k=s[0]
print(a,k)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
MIN = a[0]
keep = 0
for i in range(n):
    by = abs((a[0]/2)-a[i])
    if by <= MIN:
        MIN = by
        keep = i
print(a[0],a[keep])

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = np.zeros(n, dtype=int)
buf = input().split()
for i in range(n):
	a[i] = int(buf[i])

gamma = np.argmax(a)
alpha = a[gamma]
a[gamma] = -1
bata = a[np.argmin(np.abs(a-alpha/2))]
print(alpha, bata)

Submission status: Accepted

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

"""
参考：https://img.atcoder.jp/arc095/editorial.pdf
"""

N = int(input())
aN = list(map(int, input().split()))
aN.sort(reverse=True)

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

Submission status: Accepted

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

n, r = max(A), None
A.pop(A.index(n))
target, best_score = n / 2, float('inf')
for a in A:
    score = abs(a - target)
    if score < best_score:
        best_score = score
        r = a

print(n, r)

Submission status: Accepted

Solution code:
import bisect
n = list(map(int,input().split()))
l = list(map(int,input().split()))

l.sort()
a = bisect.bisect_left(l,l[-1]/2)

if a == 0:
  print(l[-1],l[0])
elif a == len(l)-1:
  print(l[-1],l[-2])
else:
  if abs(l[-1]/2-l[a-1]) <= abs(l[-1]/2-l[a]):
    print(l[-1],l[a-1])
  else:
    print(l[-1],l[a])

Submission status: Accepted

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

print(MAX,HALF)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())))
maxn = a.pop(-1)
maxr = a[0]

for i in a:
    if abs(i-maxn/2) < abs(maxr-maxn/2):
        maxr = i

print(maxn,maxr)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
p = abs(a[0]//2-a[1])
q = a[1]
for i in range(2,n):
    if p >= abs(a[0]//2-a[i]):
        q = a[i]
        p = abs(a[0]/2-a[i])
print(a[0],q)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
m = a[-1]
mini = a[0]
for i in range(1,n-1):
    if abs(mini-m/2) > abs(a[i]-m/2):
        mini = a[i]
print(m, mini)

Submission status: Accepted

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

ai = max(an)
tmpdiff = 10**9
aj = 0
for a in an:
    if ai > a and abs(ai/2-a) < tmpdiff:
        tmpdiff = abs(ai/2-a)
        aj = a

print(ai,aj)

Submission status: Accepted

Solution code:
N=int(input())
a=[int(i) for i in input().split()]
a.sort(key=lambda x:x)
n=a[N-1]
d=10**10
for i in range(N):
  if i<=N-2:
    if d>abs(a[i]-(n/2)):
      d=abs(a[i]-(n/2))
      r=a[i]
print(n,r)

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
x=a[-1]
l=[abs(i-x/2) for i in a]
b=a[l.index(min(l))]
print(str(x)+" "+str(b))

Submission status: Accepted

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

ai = max(a)
aj = a[0]
for i in a:
    if abs(ai - 2*i) <= abs(ai - 2*aj):
        aj = i

print(ai,aj)

Submission status: Accepted

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


def find_nearest(arr, target):
    m = min(arr)
    dist = abs(m-target)
    for a in arr:
        if abs(a-target) < dist:
            dist = abs(a - target)
            m = a
            # print(m, dist)
    return m


print(a_max, find_nearest(A, a_max/2))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
a_max = a[0]
a_med = round(a_max / 2)
min = a[0] - a[n-1]
a_answer = a[n-1]
for i in range(1, n):
    if min > abs(a[i] - a_med):
        min = a[i] - a_med
        a_answer = a[i]
print("{0} {1}".format(a_max, a_answer))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort()
n = a[N - 1]
r = -100
for e in a[:N - 1]:
    if (e - n / 2) ** 2 < (r - n / 2) ** 2:
        r = e
print(n, r)

Submission status: Accepted

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

n = A[-1]
A = A[:-1]

r_val = n//2
diff_min = float(n)

for a in A:
    diff = abs(n/2 - float(a))
    if diff_min > diff:
        diff_min = diff
        r = a

print(n,r)

Submission status: Accepted

Solution code:
from bisect import bisect_left as bl

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

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

###計算時間考察
from math import factorial as f

Submission status: Accepted

Solution code:
from bisect import bisect_left as bl

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
p = a[-1]
q = a[0]
m = p
for x in a:
  if abs(p-2*x)<m:
    q = x
    m = abs(p-2*x)
print(p,q)

Submission status: Accepted

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

a=A[-1]/2
tmp=A[-1]
ans=0
for i in range(n):
    if(abs(a-A[i]) < tmp):
        tmp=abs(a-A[i])
        ans=A[i]

print("{} {}".format(A[-1],ans))

Submission status: Accepted

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

sa = sorted(A)
from bisect import *
hv = sa[-1] / 2
ri = bisect_right(sa, hv)

if ri == 0:
    print(sa[-1], sa[ri])
elif len(sa) == 2:
    print(sa[1], sa[0])
else:
    print(sa[-1], sa[ri - 1] if abs(sa[ri - 1] - hv) < abs(sa[ri] - hv) else sa[ri])

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
A.sort()
a_half = A[-1] / 2
def binsearch(upper, lower):
  if upper - lower == 1:
    if A[upper] == A[-1] or abs(A[upper] - a_half) > abs(a_half - A[lower]):
      return lower
    else:
      return upper
  med = (upper + lower) // 2
  if A[med] == a_half:
    return med
  elif A[med] > a_half:
    return binsearch(med, lower)
  else:
    return binsearch(upper, med)
print(A[-1], A[binsearch(N - 1, 0)])

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
A.sort()
a_half = A[-1] // 2
def binsearch(upper, lower):
  if upper - lower == 1:
    if A[upper] == A[-1] or abs(A[upper] - a_half) > abs(a_half - A[lower]):
      return lower
    else:
      return upper
  med = (upper + lower) // 2
  if A[med] == a_half:
    return med
  elif A[med] > a_half:
    return binsearch(med, lower)
  else:
    return binsearch(upper, med)
print(A[-1], A[binsearch(N - 1, 0)])

Submission status: Accepted

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

t = max(a)
b = []

for i in range(n):
  if t != a[i]:
    u = abs(t / 2 - a[i])
    b.append(u)
  else:
    b.append(t)

v = a[b.index(min(b))]
print(t, v)

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
b=a.pop(-1)
print(b,min(a,key=lambda x :abs(b-2*x)))

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
M = max(A)
 
t = 7+10**9
m = M/2
p = 0
for k in range(N):
    if abs(m-A[k]) < t:
        t = abs(m-A[k])
        p = k
print(M,A[p])

Submission status: Accepted

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

a.sort()
ai = a[n-1]

aj = 10**9


if ai % 2 == 0:
    m = ai // 2
    num = 0
    for i in range(n):
        if abs(m - a[i]) < aj:
            aj = abs(m - a[i])
            num = a[i]
    aj = num

else:
    m = ai // 2
    num = 0
    for i in range(n):
        if abs(m - a[i]) < aj:
            aj = abs(m - a[i])
            num = a[i]
    aj = num

    m = ai // 2 + 1
    for i in range(n):
        if abs(m - a[i]) < aj:
            aj = abs(m - a[i])
            num = a[i]
    aj = num


print(ai, aj)

Submission status: Accepted

Solution code:
# coding:utf-8

import sys


input = sys.stdin.readline


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


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

a = max(A)
tmp = 0
b = min(A)
for i in range(N):
    x = A[i]
    if x == a: continue
    x = max(x, a - x)
    if tmp < a - x:
        b = A[i]
        tmp = a - x

print(a, b)

Submission status: Accepted

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

mx = max(A)

med = -1
min_dist = mx*999

for a in A:
    if a == mx: continue
    d = abs(a*2 - mx)
    if d < min_dist:
        min_dist = d
        med = a

print(mx, med)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

mx = max(a)
a.remove(mx)

cur = 10**18
ai = 0

for ai in a:
    if abs(ai - mx//2) < cur:
        cur = abs(ai-mx//2)
        ans = ai
        
print(mx, ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
if a[0]==100:
    print(100,0)
    exit()
m = max(a)
res = m
for i in a:
    if abs(m//2-res)>abs(m//2-i):
        res = i
print(m,res)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
X = A[-1]
X2 = (X + 1) // 2
dd = A[-1]
for i in range(N - 1):
    d = abs(X2 - A[i])
    if d < dd:
        dd = d
        Y = A[i]
print(X, Y)

Submission status: Accepted

Solution code:
def answer(aaa,max):
    half = max / 2
    bbb = []
    for i in range(len(aaa)):
        bbb.append(abs(half - aaa[i]))
    return aaa[bbb.index(min(bbb))]


n = int(input())
a = list(map(int,input().split(" ")))
b = max(a)
a.remove(b)
print(b,answer(a,b))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
mxm = max(a)
div = []
for i in range(n):
    div.append(abs(mxm/2.0-a[i]))
mini = min(div)
ind = div.index(mini)

if n == 2:
    print(max(a),min(a))
else:
    print(mxm,a[ind])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = max(a)
l = m/2
x, v = abs(a[0]-l), 0
for i in range(n):
    s = abs(a[i]-l)
    if x > s:
        x, v = s, i
if a[v] == m:
    print(m, 0)
else:
    print(m, a[v])

Submission status: Accepted

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

ans_n = A.pop()
target = ans_n / 2

ans_r = - 1
high_score = 0
for r in A:
    min_r = min(ans_n - r, r)
    if min_r >= high_score:
        high_score = r
        ans_r = r

print(ans_n, ans_r)

Submission status: Accepted

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

a = sorted(a)
ai = a[-1]
aj = -1
for j in range(n-1):
    if abs(ai/2-a[j]) < abs(ai/2-aj):
        aj = a[j]
print(ai, aj)

Submission status: Accepted

Solution code:

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

M=max(a)
M_f = float(M)
a.sort()
index=0
for i in range(len(a)):
    if a[i]>=M_f/2:
        index = i
        break
if index==0:
    print str(M) + " " +str(a[index])
else:
    if a[index]==M_f/2:
        print str(M) + " " +str(a[index])
    elif M_f/2-a[index-1]<=a[index]-M_f/2:
        print str(M) + " " + str(a[index-1])
    else:
        print str(M) + " " + str(a[index])

Submission status: Accepted

Solution code:
import math
n, aa = int(input()), list(map(int, input().split()))
l = max(aa)
r = 99999999999999
ar = sorted(aa)
for a in aa:
    if a == l:
        continue
    if abs(a - l/2) < abs(r - l/2):
        r = a
print(l, r)

Submission status: Accepted

Solution code:
n = int(input())
list_a = list(map(int, input().split()))
m = max(list_a)
search = m/2
min_a = abs(list_a[0] - search)
min_ind = 0
for i in range(n):
    if min_a > abs(list_a[i] - search):
        min_a = abs(list_a[i] - search)
        min_ind = i
if list_a[min_ind] == m:
    print(m,0)
else:
    print(m, list_a[min_ind])

Submission status: Accepted

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
b=max(a)
a.remove(b)
d=b//2
a1=[]
for i in range(len(a)):
    a1.append(abs(d-a[i]))
c=min(a1)
if d+c in a:
    print("{} {}".format(b,d+c))
else:
    print("{} {}".format(b,d-c))

Submission status: Accepted

Solution code:
# coding:utf-8

INF = float('inf')


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


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

n = max(A)
r = max(A)
tmp = 0
for i in range(N):
    a = A[i]
    if a == n: continue
    if a < n - a: a = n - a
    if tmp <= n - a:
        r = A[i]
        tmp = n - a

print(n, r)

Submission status: Accepted

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

a_i = max(a)
a2 = sorted(a, key = lambda x: abs(2 * x - a_i))

a_j = float('inf')
j = 0
while a_j >= a_i:
    a_j = a2[j]
    j += 1

print(a_i, a_j)

Submission status: Accepted

Solution code:
import sys
Input = sys.stdin.readline
#Input = input

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

c_n = max(a)
c_r = None
c_r_err = float("inf")
for i in a:
    if i == c_n:
        continue
    err = abs((c_n/2) - i)
    if err < c_r_err:
        c_r = i
        c_r_err = err

print("{0} {1}".format(c_n, c_r))

Submission status: Accepted

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

ma = max(a)
ma2 = ma/2
mi = 999999999999.0
mii = -1
for i in a:
    if abs(ma2 - i) < mi and i != ma:
        mi = abs(ma2 - i )
        mii = i

print(ma,mii,sep=" ")

Submission status: Accepted

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

A.sort()
if n == 2:
    print(A[1],A[0])
else:
    ans_a = A[n-1]

    left = 0
    right = n-1
    while True:
        if left == right:
            ans_b = A[left]
            break
        elif left + 1 == right:
            if abs(A[left]-ans_a/2) < abs(A[right]-ans_a/2):
                ans_b = A[left]
            else:
                ans_b = A[right]
            break
        elif ans_a//2 < A[(left+right)//2]:
            right = (left+right)//2
        else:
            left = (left+right)//2

    print(ans_a,ans_b)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
maxim = 0
for x in a:
    maxim = max(x,maxim)
delta = a
halfFloor = maxim//2
halfCeil = halfFloor
if maxim%2 == 1:
    halfCeil += 1
delta = maxim
for x in a:
    if x == maxim:
        continue
    if x <= halfFloor:
        if halfFloor - x < delta:
            candidate = x        
            delta = halfFloor - x
    else:
        if x - halfCeil < delta:
            candidate = x
            delta = x - halfCeil
print(maxim,candidate)

Submission status: Accepted

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

mid = arr[-1]/2
min_ = float('inf')
tmp = 0
for x in arr[:-1]:
    if abs(mid-x) < min_:
        tmp = x
        min_ = abs(mid-x)

print('{0} {1}'.format(arr[-1],tmp))

Submission status: Accepted

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

mindist = a[n - 1]

for j in range(n - 1):
    dist = int(abs(a[n - 1] / 2 - a[j]))
    if dist < mindist:
        aj = a[j]
        mindist = dist

print(a[n - 1], aj)

Submission status: Accepted

Solution code:
n = int(input())
lis = list(map(int,input().split()))
lis.sort(reverse = True)
cou = lis[1]
for i in range(2,n-1):
  if abs(cou - (lis[0]/2)) > abs(lis[i] - (lis[0]/2)):
    cou = lis[i]
print(lis[0],cou)

Submission status: Accepted

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

a.sort()

ans1=max(a)
ans2=0
b=0
c=0
lb=[]
lc=[]

if ans1%2==0:
    b=ans1/2
    c=ans1/2
else:
    b=(ans1+1)/2
    c=b-1

for i in a:
    if abs(i-b)<abs(ans2-b):
        ans2=i
    if abs(i-c)<abs(ans2-c):
        ans2=i

print(str(ans1)+" "+str(ans2))

Submission status: Accepted

Solution code:
def iin(): return int(input())
def nl(): return list(map(int, input().split()))

n = int(input())
a = nl()

a_sorted_1 = sorted(a)
ai = a_sorted_1[-1]

a_sorted_2 = sorted(a_sorted_1[:-1], key = lambda x: abs(x - ai / 2))
aj = a_sorted_2[0]
print(ai, aj)

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = inp()
aa = inpl()
aa.sort()
MAX = aa[-1]
dist = INF
for a in aa:
	tmp = abs(MAX/2-a)
	if tmp < dist:
		dist = tmp
		ans = a

print(MAX,ans)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a_list = [int(i) for i in input().split()]
res1 = max(a_list)
a_list.remove(res1)
res_med = res1 / 2
res2 = a_list[np.argmin([abs(i - res_med) for i in a_list])]
print(str(res1)+' '+str(res2))

Submission status: Accepted

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

A.sort()

if len(A) == 2:
    print(A[1], A[0])
else:
    a = A[-1]
    k = a / 2
    B = [a for a in A if a <  k]
    C = [a for a in A if a >= k]

    if k - B[-1] > C[0] - k:
        print(a, C[0])
    else:
        print(a, B[-1])

Submission status: Accepted

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

a_list.sort()
max_num = a_list.pop(-1)
margin = max_num
r = 0
for a in a_list:
    m = abs(max_num/2 - a)
    if margin >= m:

        margin = m
        r = a

print(str(max_num) + " " + str(r))

Submission status: Accepted

Solution code:
n = int(input())
ai = 0
aj = 0
nums = list(map(int, input().split()))
nums.sort()
ai = nums[n-1]
i = 0
while nums[0] < ai//2:
    aj = nums[0]
    del nums[0]
else:
    if ai > nums[0] + aj:
        aj = nums[0]
print(str(ai) + " " + str(aj))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans1=max(a)
ans2=min(a)
mean=ans1 / 2.0


for i in a:
    if abs(mean-i) < abs(mean-ans2):
        ans2=i

print(ans1,ans2)

Submission status: Accepted

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

m = a[-1] / 2
ans = 0
for i in range(n - 1):
    if abs(a[i] - m) <= abs(ans - m):
        ans = a[i]

print(a[-1], ans)

Submission status: Accepted

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

p = max(A)

As = sorted(A)

q = 0

for x in As:
  if abs(p/2-x) < abs(p/2-q):
    q = x
    
print(p,q)

Submission status: Accepted

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

max_a = max(A)
s_set = set()
l_set = set()
for a in A:
    if(a <= max_a//2):
        s_set.add(a)
    else:
        l_set.add(a)

s_max = max(s_set | {0})
l_min = min(l_set | {max_a})

if(s_max >= (max_a - l_min)):
    print(max_a, s_max)
else:
    print(max_a, l_min)

Submission status: Accepted

Solution code:
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

def solve(A):
    t = A[-1] / 2
    b = INF
    ans = -1
    for a in A:
        if abs(t - a) < b:
            b = abs(t - a)
            ans = a

    return A[-1], ans

def main():
    n = int(input())
    A = list(sorted(list(map(int, input().split()))))
    print(*solve(A))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
import math

def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)

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


# Choose the largest element
largestA = max(A)
max_n = A.index(largestA)

min_dif = 10000000000
min_n = -1
for n in range(N):
    if n == max_n:
        continue
    dif = int(abs(A[n] - int(largestA / 2)))
    if dif < min_dif:
        min_dif = dif
        min_n = n
        # print(min_dif)
        # print(min_n)


# print(nCr(largestA, A[min_n]))
print(largestA, A[min_n])

Submission status: Accepted

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

    n = A[0]

    half = n / 2
    diff = 10 ** 100

    A.remove(n)

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

    print(n, r)


main()

Submission status: Accepted

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

ai = max(A)
while ai in A:
    A.remove(ai)

aj_ideal = ai/2

A_diff = [abs(a-aj_ideal) for a in A]
A_diff_closest0 = min(A_diff)
aj = A[A_diff.index(A_diff_closest0)]

print(ai,aj)

Submission status: Accepted

Solution code:
n=int(input())
s=list(map(int,input().split()))
s.sort()
c=float("inf")
a=max(s)
for i in s[0:n]:
    x=abs(a/2-i)
    if x<c:
        c=x
        b=i
print(a,b)

Submission status: Accepted

Solution code:
n = int(input())

a = list(map(int,input().split()))
b = sorted(a)
c = b.copy()
Mave = max(c)/2
del b[n-1]

hantei =[]
for i in b:
    hantei.append(abs(Mave-i))

print(str(max(c))+' '+str(b[hantei.index(min(hantei))]))

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())

arr = map(int,raw_input().split())

arr.sort()
mx = arr.pop()

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

print mx,getNearestValue(arr,mx/2.0)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a=sorted(a,reverse=True)
comb_n=a[0]
a=a[1:]
r_ind=int(comb_n/2)

ans=0
for i in range(len(a)-1):
     if abs(a[i]-r_ind)<=abs(a[i+1]-r_ind):
          ans=a[i]
          break
print(comb_n,ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort()
n = a[-1]
r = 0
for i in range(N-1):
  if min(a[i], n-a[i])>min(r, n-r):
    r = a[i]
print(n, r)

Submission status: Accepted

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

def main():
    A.sort()
    max_num = A[len(A) - 1]
    mid_num = max_num / 2

    curr = A.pop(0)
    d = abs(mid_num - curr)
    for a in A:
        next_d = abs(mid_num - a)
        if d <= next_d:
            break
        curr = a
        d = next_d
    print(max_num, curr)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
MA = max(A)
N = MA/2
X = max(A)-1
for i in range(n):
    if abs(A[i] - N) < X and A[i] != MA:
        X = abs(A[i] - N)
        k = i       
print('{} {}'.format(MA, A[k]))

Submission status: Accepted

Solution code:
import sys
N = int(input())
A = list(map(int, input().split()))
if len(A) == 2:
  print(max(A),min(A))
  sys.exit()
a = max(A)
b = a/2
import numpy as np
def getNearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]
c = getNearestValue(A,b)
print(a,c)

Submission status: Accepted

Solution code:
N = int(input().strip())
A = list(map(int,input().strip().split(' ')))

import numpy as np
sortA = np.array(sorted(A))
a_large = sortA[-1]
sortA = np.delete(sortA,-1,0)
half_of_a_large = np.array([a_large/2 for i in range(N-1)])
a_small = sortA[np.argmin(abs(np.array([sortA[i]-a_large/2 for i in range(N-1)])))]
print(a_large,a_small)

Submission status: Accepted

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

a.sort()

q = int(a[-1])

a.pop(-1)

max_p = 0
index = 0
for i in range(len(a)):
	p = min(a[i],(q-a[i]))
	if(max_p<p):
		max_p = int(p)
		index = i

print(q,a[index])

Submission status: Accepted

Solution code:
import sys

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

a.sort()

ai = a.pop()

half_ai = ai / 2

min_diff = sys.maxsize
for i in a:
    diff = abs(half_ai - i)
    if diff < min_diff:
        aj = i
        min_diff = diff

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