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:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    max_A = max(A)
    half_max_A = max_A / 2
    dist = [abs(half_max_A - a) for a in A]
    ans = 0
    best = 1000000005
    for i, d in enumerate(dist):
        if best > d and max_A > A[i]:
            best = d
            ans = A[i]

    print(max_A, ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
data = int(input())
array = list(map(int, input().split()))
high = max(array)
array.remove(high)
p = high/2
a_m = [abs(array[i]-p) for i in range(data-1)]
print(high, array[a_m.index(min(a_m))])

Submission status: Accepted

Solution code:
n = int(input())
a  = list(map(int,input().split()))
N = max(a)
res = 10**10
k = 0
for i in range(n):
    
    if abs(a[i]-N/2) <= res:
        res = abs(a[i] -N/2)
        k = i

print(N,a[k])

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    n = A[-1]
    r = 0
    b = n  / 2
    temp = 10**20
    for i in A:
        if temp > abs(i - b):
            temp = abs(i-b)
            r = i
    print(n, r)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split(" ")))
a.sort()
ai = a.pop()
aj = a[0]
diff = abs(ai - 2 * aj)


for i in range(1, len(a)):
    if diff > abs(ai - 2 * a[i]):
        aj = a[i]
        diff = abs(ai - 2 * a[i])
print(ai, aj)

Submission status: Accepted

Solution code:
def main():
  n = int(input())
  a = list(map(int, input().split()))
  a.sort()
  
  r = 0
  c = a[-1] / 2
  for i in range(n-1):
    if abs(c-r) > abs(c-a[i]):
      r = a[i]
  ans = "{} {}".format(a[-1], r)
  print(ans)

  
if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))

    n = max(A)
    a = -1
    d = n
    for e in A:
        if e == n:
            continue
        if abs(e - n/2) < d:
            a = e
            d = abs(e - n/2)
    
    print(n, a)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

def main():
    N = int(sys.stdin.readline())
    A = list(map(int, sys.stdin.readline().rstrip().split()))

    n = max(A)
    a = -1
    d = n
    for e in A:
        if e == n:
            continue
        if abs(e - n/2) < d:
            a = e
            d = abs(e - n/2)
    
    print(n, a)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, math
sys.setrecursionlimit(10 ** 6)
from collections import deque, defaultdict, Counter
from operator import itemgetter

def main():
    N = int(input())
    A = list(map(int, sys.stdin.readline().rstrip().split()))

    n = max(A)
    a = -1
    d = n
    for e in A:
        if e == n:
            continue
        if abs(e - n/2) < d:
            a = e
            d = abs(e - n/2)
    
    print(n, a)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

a.sort()
ans = 114514191981036436433-4
s = 0
nn = a[n]/2
for i in range(n+1):
    if ans > abs(nn-a[i]):
        ans = abs(nn-a[i])
        s = i
        
print(a[n],a[s])

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    _ = int(input())
    A = list(map(int, input().split()))
    A.sort()
    n = A[-1]
    ans = -1
    for a in A:
        if a + 1 <= n / 2:
            ans = a
        else:
            b = n - a
            if b > ans:
                ans = a

    print(n, ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ma=max(a)
ma=ma//2
aaa=max(a)
ans=10**10
for i in range(n):
    if abs(ma-a[i])<ans and a[i]!=aaa:
        ans=abs(ma-a[i])
        aaaaaa=a[i]
print(max(a),aaaaaa)

Submission status: Accepted

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


# xCy = xCx-y
# あるaについて，a/2に近い方が良い
# -> |aj - a / 2|となるajを選ぶ (a以外)

maxA = max(A)
mv = float("inf")
aj = None
for a in A:
    if a != maxA:
        value = abs(a - maxA // 2)
        if value < mv:
            mv = value
            aj = a

print(maxA, aj)

Submission status: Accepted

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

a.sort()

N,K = a[n-1],a[0]

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

print(N,K)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans1 = max(a)
diff = min(ans1//2, ans1//2 + 1)
ans2 = ans1
for x in a:
  if x == ans1:
    continue
  d = min(abs(ans1//2 - x), abs(ans1//2 + 1 - x))
  if d <= diff:
    diff = d
    ans2 = x
print('{} {}'.format(ans1, ans2))

Submission status: Accepted

Solution code:
from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))
a.sort()
ma = a[-1]
mid = ma / 2 # ma/2に最も近いものをとってくればよい

idx = bisect_left(a, mid)

if abs(a[idx] - mid) < abs(a[idx-1] - mid):
	ans_idx = idx
else:
	ans_idx = idx - 1

print(ma, a[ans_idx])

Submission status: Accepted

Solution code:
from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))
a.sort()
ma = a[-1]
mid = ma / 2 # ma/2に最も近いものをとってくればよい

idx = bisect_left(a, mid)

if abs(a[idx] - mid) < abs(a[idx-1] - mid):
	ans_idx = idx
else:
	ans_idx = idx - 1

print(ma, a[ans_idx])

Submission status: Accepted

Solution code:
import bisect
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
m = max(a)
half_idx = bisect.bisect_left(a, m//2)

def ncr(n, r, p):
    num = den = 1
    for i in range(r):
        num = (num * (n - i)) % p
        den = (den * (i + 1)) % p
    return (num * pow(den, p - 2, p)) % p
p=10**9+7 

if n == 2:
    print(a[1], a[0])
    exit()

if 1 <= half_idx < n-1:
    if min(a[half_idx-1], m-(a[half_idx-1])) >= max(min(a[half_idx], m-(a[half_idx])), min(a[half_idx+1], m-(a[half_idx+1]))):
        print(m, a[half_idx-1])
    elif min(a[half_idx], m-(a[half_idx])) >= max(min(a[half_idx-1], m-(a[half_idx-1])), min(a[half_idx+1], m-(a[half_idx+1]))):
        print(m, a[half_idx])
    elif min(a[half_idx+1], m-(a[half_idx+1])) >= max(min(a[half_idx], m-(a[half_idx])), min(a[half_idx-1], m-(a[half_idx-1]))):
        print(m, a[half_idx+1])
elif half_idx == 0:
    if min(a[half_idx], m-(a[half_idx])) >= min(a[half_idx+1], m-(a[half_idx+1])):
        print(m, a[half_idx])
    elif min(a[half_idx+1], m-(a[half_idx+1])) >= min(a[half_idx], m-(a[half_idx])):
        print(m, a[half_idx+1])
elif half_idx == n-1:
    if min(a[half_idx], m-(a[half_idx])) >= min(a[half_idx-1], m-(a[half_idx-1])):
        print(m, a[half_idx])
    elif min(a[half_idx-1], m-(a[half_idx-1])) >= min(a[half_idx], m-(a[half_idx])):
        print(m, a[half_idx-1])

Submission status: Accepted

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

import bisect
a.sort()

center = a[-1]//2

index = bisect.bisect_left(a,center)

if a[index] != center:
    if index > 0 and center - a[index-1] < a[index] - center:
        index -= 1
        
if index == n-1:
    index -= 1
    
print(a[-1],a[index])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N = ii()
A = sorted(li())
half = A[-1]//2

ind = bisect.bisect_left(A, half)

if (N%2==0 and A[ind]!=half) or (N%2==1 and A[ind]-half > 1):
    if ind > 0 and half - A[ind-1] <= A[ind] - half:
        ind -= 1

print(A[-1], A[ind])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N = ii()
A = sorted(li())
half = A[-1]//2

ind = bisect.bisect_left(A, half)

if A[ind]!=half:
    if ind > 0 and half - A[ind-1] < A[ind] - half:
        ind -= 1
if ind == N-1:
    ind -= 1

print(A[-1], A[ind])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N = ii()
A = sorted(li())
half = A[-1]//2
#if N % 2 == 0
ind = bisect.bisect_left(A, half)
#if ind > 0 and A[ind] - half > A[ind-1] - half:
    #ind -= 1
if A[ind]!=half:
    if ind > 0 and half - A[ind-1] < A[ind] - half:
        ind -= 1
if ind == N-1:
    ind -= 1
print(A[-1], A[ind])

Submission status: Accepted

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

def closest(x):
    res = None
    min_diff = None
    for k in a:
        if k == m:
            continue
        diff = abs(k - x)
        if res is None or min_diff > diff:
            min_diff = diff
            res = k
    return res

print(m, closest(m // 2))

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
a=sorted(a)
m=a[-1]
r=max(a[:-1],key=lambda x:min(x,m-x))
print(m,r)

Submission status: Accepted

Solution code:
def main3():
    input()
    t = sorted(list(map(int, input().split())))
    ma = t.pop(-1)
    r = min(t, key=lambda x: abs(x - ma / 2))
    print(ma, r)

if __name__ == '__main__':
    main3()

Submission status: Accepted

Solution code:
import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
s=a[n-1]
a[n-1]=s*10
k=bisect.bisect_left(a,s//2)
b=a[k-1]
c=a[k]
if abs(b*2-s)<abs(c*2-s):
  ans=b
else:
  ans=c
print(s,ans)

Submission status: Accepted

Solution code:
from math import factorial
N = int(input())
A = list(map(int,input().split()))
t, j = float("INF"), -1
max_A = max(A)
A.remove(max_A)
for i in range(N-1):
  if abs(max_A//2 - A[i]) < t:
    t = abs(max_A//2 - A[i])
    j = i
print(max_A, A[j])

Submission status: Accepted

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from bisect import bisect_left
from operator import lt, le
def findNearstValue(lst, val, left=True):
    """ソート済のリストから，valに最も近い要素を返す.
    @param lst: ソート済のリスト
    @param left:
        lv < val < rv，val-lv == rv-val のとき，
        Trueならばlvを，Falseならばrvを選択する
    @return もっともvalに値が近いlstの要素
    """
    pos = bisect_left(lst, val)
    if pos == 0: return lst[0]
    if pos == len(lst): return lst[-1]
    lv, rv = lst[pos-1:pos+1]
    op = le if left else lt
    return lv if op(val-lv, rv-val) else rv

def main():
    n = II()
    aa = MII()
    aa.sort()
    ans_n = aa[-1]
    m = ans_n/2
    ans_r = findNearstValue(aa, m)
    print(ans_n, ans_r, end= ' ')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
N = int(input())
ListA = list(map(int,input().split()))
ListA.sort()
Minj = 10e8
Maxj = ListA[-1]

for j in range(N-1):
    if abs(ListA[j]*2-ListA[-1])<Minj:
        Maxj = ListA[j]
        Minj = min(abs(ListA[j]*2-ListA[-1]),Minj)

    else:
        continue


print(ListA[-1],Maxj)

Submission status: Accepted

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from bisect import bisect_left

def getNearstValue(lst, num):
    idx = bisect_left(lst, num+1)
    if abs(lst[idx]-num) > abs(lst[idx-1]-num):
        idx -= 1
    return idx

def main():
    n = II()
    aa = MII()
    if n == 2: print(*aa); exit(0)
    aa.sort()
    ans_n = aa[-1]
    m = ans_n/2
    idx = getNearstValue(aa, m)
    ans_r = aa[idx]
    print(ans_n, ans_r, end= ' ')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from bisect import bisect_left

def main():
    n = II()
    aa = MII()
    if n == 2: print(*aa); exit(0)
    aa.sort()
    ans_n = aa[-1]
    m = ans_n/2
    idx = bisect_left(aa, m+1)
    ans_r = aa[idx] if idx!=n-1 else aa[idx-1]
    if abs(aa[idx]-m) > abs(aa[idx-1]-m):
        ans_r = aa[idx-1]
    print(ans_n, ans_r, end= ' ')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
import numpy as np
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """
    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

def main():
    n = II()
    aa = MII()
    if n == 2: print(*aa); exit(0)
    aa.sort()
    maxa = aa[-1]
    m = maxa/2
    a = getNearestValue(aa, m)
    print(maxa, a, end= ' ')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())))
x = a.pop()
y = a[0]
m = abs(x/2 - a[0])
for i in range(1,n-1):
    if abs(x/2-a[i]) < m:
        y = a[i]
        m = abs(x/2-a[i])
print(x,y)

Submission status: Accepted

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

alist.sort(reverse=True)

n=alist[0]
min_func=10**9
r=0
for i in range(1,N):
  if abs(n-2*alist[i])<min_func:
    min_func=abs(n-2*alist[i])
    r=alist[i]

print(n,r)

Submission status: Accepted

Solution code:

n=int(input())
A=sorted(list(map(int, input().split())))
amax=max(A)
half=amax/2

ans=0
now=amax
for a in A:
  if abs(a-half)<=now and a<amax:
    now=abs(a-half)
    ans=a
print(amax, ans)

Submission status: Accepted

Solution code:
n = int(input())
A = sorted(map(int, input().split()))
ans_n = A[-1]
ans_r = -1
for a in A:
  if ans_r < min(a, ans_n - a):
    ans_r = a
print(ans_n, ans_r)

Submission status: Accepted

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

from bisect import bisect_left
ans_n = a[-1]

p = bisect_left(a, (ans_n+1)//2)
ans_r = a[p] if p != n-1 else a[p-1]
if abs(a[p] - ans_n/2) > abs(a[p-1] - ans_n/2):
  ans_r = a[p-1]

print(ans_n, ans_r)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
a=sorted(a)
n=a[-1]
r=a[0]
r_max=a[0]
if n//2<r:
    r_max=n-a[0]
for i in range(N-1):
    r_kari=a[i]
    r_=r_kari
    if n//2<r_:
        r_=n-r_
    if r_max<r_:
        r_max=r_
        r=r_kari
    #print(r_max)
print(str(n)+" "+str(r))

Submission status: Accepted

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

numbers.sort()

n = numbers.pop()
r = min(numbers, key=lambda x: abs(x - n / 2))  # N

print(n, r)

Submission status: Accepted

Solution code:
from math import factorial

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


max_num = A[-1]
medium = max_num / 2

diff = []
for a in A:
    diff.append(abs(medium-a))

min_index = diff.index(min(diff))
print(max_num, A[min_index])

Submission status: Accepted

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

def obj_func(v, base):
  return abs(v - base)

ai = aj = max(A)
base = ai / 2
min_obj = 10**10
for a in A:
  if a == ai:
    continue
  obj = obj_func(a, base)
  if obj < min_obj:
    min_obj = obj
    aj = a

print(ai, aj)

Submission status: Accepted

Solution code:
n = int(input())
list_A = list(map(int, input().split()))
list_A.sort()
max_value = max(list_A)
a = max_value/2
b = pow(10, 10)
c = 0
for num in list_A:
    if abs(a-num) < b:
        b = abs(a-num)
        c = num

print(max_value, c)

Submission status: Accepted

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

b=len(a)
Z=a[-1]
X=0
for i in range(1,n-1):
  if abs((Z/2)-a[X])>abs((Z/2)-a[i]):
    X=i



print(a[-1],a[X])

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
mi=float("inf")
piv=0
pivid=[0]*n
id=1
cnb=[0]*n
for i in range(n):
    piv=a[i]
    mi=float("inf")
    while id<n:
        #print(a,piv,pivid,id,a[id],mi)
        if abs(piv / 2 - a[id]) < mi:
            mi = abs(piv / 2 - a[id])
            id = id + 1
        else:
            id=id-1
            break

        #input()
    pivid[i]=min(id,n-1)

print(a[0],a[pivid[0]])

Submission status: Accepted

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

m = max(a)

if m % 2 == 0:
  h = m // 2
  
  c = sys.maxsize
  for i in range(n):
    if m == a[i]:
      continue
    
    if c > abs(h-a[i]):
      c = abs(h-a[i])
      ans = a[i]
    
  print(m, ans)
  
else:
  h1 = m // 2
  h2 = h1 + 1
  c = sys.maxsize
  
  for i in range(n):
    if m == a[i]:
      continue
    
    if c > abs(h1-a[i]):
      c = abs(h1-a[i])
      ans = a[i]    
      
    if c > abs(h2-a[i]):
      c = abs(h2-a[i])
      ans = a[i]
      
  print(m,ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
M = max(a)
m = M / 2

diff = 10 ** 9
r = None
for i in range(n):
    if a[i] == M:
        continue
    else:
        if abs(m - a[i]) < diff:
            diff = abs(m - a[i])
            r = a[i]

print(M, r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ma = max(a)
    ma2 = ma/2
    a.remove(ma)
    ans = 0
    diff = 10**10
    for i in a:
        if diff > abs(ma2-i):
            ans = i
            diff = abs(ma2-i)
    print(ma, ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())))
ai = max(A)
ai_idx = A.index(ai)
half_maxA = ai // 2 if ai % 2 == 0 else ai // 2 + 1
for idx, a in enumerate(A):
    if ai_idx == idx:
        continue
    if idx == 0:
        aj = a
    else:
        if abs(a - half_maxA) < abs(aj - half_maxA):
            aj = a
print(ai, aj)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
y=a[-1]
diff=10**9+2
for i in a[:-1]:
    diff=min(diff,max(i,y-i))
x=-1
for i in a[:-1]:
    if max(i,y-i)==diff:
        x=i
        break
print(y,x)

Submission status: Accepted

Solution code:
def sq(a, b, mod):  # aのb乗を剰余,kは初期値#20191116-D-Knight
    if b == 0:
        return 1
    elif b % 2 == 0:
        return sq(a, b // 2, mod)**2 % mod
    else:
        return sq(a, b - 1, mod) * a % mod


def nCk(n, k, mod=10 ** 9 + 7):
    x = max(k, n - k)
    y = min(k, n - k)
    kkai = 1
    for i in range(2, y + 1):
        kkai = (kkai * i) % mod
    nkkai = 1
    for i in range(x + 1, n + 1):
        nkkai = (nkkai * i) % mod
    answer = sq(kkai, mod - 2, mod) * nkkai % mod
    return answer


n = int(input())
alist = sorted(map(int, input().split()))
aset = set(alist)
ai = alist[-1]
aset.remove(ai)
target = ai // 2
sbn = [abs(alist[i] - target) for i in range(n - 1)]
j = min(sbn)
aj = (target + j) if (target + j) in aset else target - j
print(ai, aj)

Submission status: Accepted

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

i = a[-1]
ave_index = bisect_left(a,i/2)
if ave_index == 0:
    j=a[0]
elif ave_index == n-1:
    j=a[-2]
else:
    if a[ave_index]*2 - i < i - a[ave_index-1]*2:
        j = a[ave_index]
    else:
        j = a[ave_index-1]
print(i,j)

Submission status: Accepted

Solution code:
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n=int(input())
a=sorted(list(map(int,input().split())))
b=a[n-1]
a.pop(n-1)
ans=0
for i in range(n-1):
    if abs(b/2-a[ans])>abs(b/2-a[i]):
        ans=i
print(str(b)+" "+str(a[ans]))

Submission status: Accepted

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

ans1 = max(a)
ans2 = 0

dif = ans1
for i in a:
  if dif > abs(i-ans1/2) and i != ans1:
    dif = abs(i-ans1/2)
    ans2 = i
    
print(ans1, ans2)

Submission status: Accepted

Solution code:
import bisect
n=int(input())
a=list(map(int,input().split()))
a.sort()
idx=bisect.bisect_left(a,a[-1]//2)
if n==2:
  print(a[1],a[0])
  exit()
if idx==0:
  print(a[-1],a[idx])
else:
  if a[idx]-a[-1]//2<=a[-1]//2-a[idx-1]:
    print(a[-1],a[idx])
  else:
    print(a[-1],a[idx-1])

Submission status: Accepted

Solution code:
import numpy as np

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

max_n = a[-1]
del a[-1]

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

print(max_n,getNearestValue(a,half_n))

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

a = max(A)
b = None
used = False
for i in A:
    if i == a and not used:
        used = True
    elif not b or abs(a // 2 - b) > abs(a // 2 - i):
        b = i

print(a, b)

Submission status: Accepted

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

if n==2:
    print(max(a), min(a))
else:
    left=max(a)
    ideal_right=left/2
    right=min(a, key=lambda x:abs(x-ideal_right))
    print(left, right)

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
n=max(a)
print(n,min((abs(n/2-i),i)for i in a)[1])

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
a.sort()
b=a[-1]
c=a[0]
d=b/2-c
for i in a:
    if d>abs(b/2-i):
        c=i
        d=abs(b/2-i)
print(b,c)

Submission status: Accepted

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

b=max(a)
d=b/2

c=abs(d-a[0])
#print(c)
if a[0]==b:
  c=99999
ans=a[0]
for i in a:
  #print(abs(i-d))
  if i==b:
    continue
  if abs(i-d)<c:
    ans=i
    c=abs(i-d)
    
print(b,end=" ")
print(ans)

Submission status: Accepted

Solution code:
def d_binomial_coefficients():
    from bisect import bisect_left
    N = int(input())
    A = sorted([int(i) for i in input().split()])  # ソートしておく

    n = A[-1]  # comb(n, r) の n をこの値以外にする理由はない
    r = min(A[:-1], key=lambda x: abs(n / 2 - x))
    return '{0} {1}'.format(n, r)

print(d_binomial_coefficients())

Submission status: Accepted

Solution code:


def submit():
    n = int(input())
    a = list(map(int, input().split()))
    
    a_max = max(a) # -> n
    a.remove(a_max)

    r_best = a_max / 2
    a_diff = [(i, abs(e - r_best)) for i, e in enumerate(a)]
    a_diff.sort(key=lambda x: x[1])
    print(a_max, a[a_diff[0][0]])


submit()

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
 
a=max(A)
 
B=[]
 
for i in range(n):
    if A[i]==a:
        B.append(a)
    else:
    	B.append(abs(A[i]-a/2))
 
ind=B.index(min(B))
 
b=A[ind]
 
print(a,b)

Submission status: Accepted

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

A.sort()

m=A[-1]
B=[0 for i in range(0,N-1)]
for i in range(0,N-1):
    B[i]=min(A[i],m-A[i])

r=max(B)
if r in A:
    print(m,r)
else:
    print(m,m-r)

Submission status: Accepted

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

Submission status: Accepted

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

a.sort(reverse=True)
h = a[0] / 2
m = a[1] - h
ans = 1
for i in range(2, n):
    if (abs(a[i] - h) < m):
        m = abs(a[i] - h)
        ans = i


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

Submission status: Accepted

Solution code:
# coding: utf-8

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

A.sort()

ansi=A[-1]

def bin_isOK(index,key):
    if A[index] >= key:
        return True
    else:
        return False


def binary_search(key):
    ng = -1
    ok = len(A)

    while abs(ok - ng) >1:
        mid = (ok + ng)//2

        if bin_isOK(mid,key):
            ok = mid
        else:
            ng = mid
    
    return ok

Index=binary_search(ansi/2)

if abs(A[Index]-(ansi/2))<abs(A[Index-1]-(ansi/2)):
    ansj=A[Index]
else:
    ansj=A[Index-1]

print(ansi,ansj)

Submission status: Accepted

Solution code:
# coding: utf-8
from math import ceil
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=False)
top = A[-1]
half = ceil(top / 2)
b = float("inf")
for i in range(N-1):
    if abs(half - b) > abs(half - A[i]):
        b = A[i]
print(top, b)

Submission status: Accepted

Solution code:
import bisect
def solve():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()

    mx = [-1, -1]
    for i in range(N):
        idx = bisect.bisect_left(A,A[i]/2)
        if idx == 0:
            mx = [max(A[i],A[idx]), min(A[i],A[idx])]
            continue

        if abs(A[i]/2 - A[idx]) < abs(A[i]/2 - A[idx-1]):
            mx = [max(A[i],A[idx]), min(A[i],A[idx])]
        else:
            mx = [max(A[i],A[idx-1]), min(A[i],A[idx-1])]
    
    print(*mx)
    
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N=int(input())
A=sorted(list(map(int,input().split())))
n,r=A.pop(),0
index=0
for i,j in enumerate(A):
    num=min(n-j,j)
    if num>r:
        index=i
        r=num
print(n,A[index])

Submission status: Accepted

Solution code:
n = int(input())

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

A = list(sorted(A))

a = A[-1]
b = a//2
ans = 0
if n == 2:
    print(a, A[0])
else:
    m = A[-1]
    for i in A[:-1]:
        if m >= abs(b - i):
            m = abs(b - i)
            ans = i

    print(a, ans)

Submission status: Accepted

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

maxa = 0
ai = 0
for i in range(N):
    if A[i] > maxa:
        ai = i
        maxa = A[i]
maxa //= 2

res = 0
mind = 10**18
for i in range(N):
    if i==ai: continue
    d = abs(A[i]-maxa)
    if d < mind:
        mind = d
        res = i

print(maxa, A[res]//2)

Submission status: Accepted

Solution code:
from bisect import bisect_left as bl

def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()
    M = A[-1]//2
    k = bl(A,M)
    if M in A:
        print(*[A[-1],M])
        exit()
    if k == N-1:
        ans = [A[-1],A[k-1]]
        print(*ans)
        exit()
    if k == 0:
        print(*[A[-1],A[0]])
        exit()
    if A[-1]%2 == 0:
        if abs(A[k-1]-M) <= abs(M-A[k]) and abs(A[k-1]-M) <= abs(A[k+1]-M):
            ans = [A[-1],A[k-1]]
        elif abs(A[k+1]-M) <= abs(M-A[k]) and abs(A[k+1]-M) <= abs(A[k-1]-M):
            ans = [A[-1],A[k+1]]
        elif abs(A[k]-M) <= abs(M-A[k-1]) and abs(A[k]-M) <= abs(A[k+1]-M):
            ans = [A[-1],A[k]]
    else:
        if abs(A[k-1]-M) < abs(M-A[k]) and abs(A[k-1]-M) < abs(A[k+1]-M):
            ans = [A[-1],A[k-1]]
        elif abs(A[k+1]-M) <= abs(M-A[k]) and abs(A[k+1]-M) <= abs(A[k-1]-M):
            ans = [A[-1],A[k+1]]
        elif abs(A[k]-M) <= abs(M-A[k-1]) and abs(A[k]-M) <= abs(A[k+1]-M):
            ans = [A[-1],A[k]]
    
    print(*ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
mx=max(a)
hf=0
for x in a:
  if abs(mx-2*hf)>abs(mx-2*x):
    hf=x
print(mx,hf)

Submission status: Accepted

Solution code:
N=int(input())
a=sorted(list(map(int,input().split())))
n=a[-1]
tmp=0
if n%2==0:
  ideal=n//2
  for i in range(N-1):
    if abs(ideal-tmp)>abs(ideal-a[i]):
      tmp=a[i]
else:
  ideal1=(n-1)//2
  ideal2=ideal1+1
  for i in range(N-1):
    if abs(ideal1-tmp)>abs(ideal1-a[i]) or abs(ideal2-tmp)>abs(ideal2-a[i]):
      tmp=a[i]
print(' '.join([str(n),str(tmp)]))

Submission status: Accepted

Solution code:
from bisect import bisect_left as bl,bisect_right as br
n=int(input())
l=list(map(int,input().split()))
l.sort()
pre=10**9
mm=l[-1];p=0
for i in range(max(0,bl(l,l[-1]//2)-2),min(n,l[-1]//2+3)):
    if abs(mm/2-l[i])<pre:pre=abs(mm/2-l[i]);p=i
print(mm,l[p])