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())
arr = [int(a) for a in input().split()]

i = max(arr)
arr.remove(i)
j = min(arr, key=lambda a: min(abs(i//2-a), abs((i+1)//2-a)))

print(i, j)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

n = max(A)

if n % 2 == 0:
    nn = n // 2
else:
    nn = (n + 1) // 2

minA = n
aa = n
for a in A:
    if abs(a - nn) <= minA:
        minA = abs(a - nn)
        aa = a
print(n, aa)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ans = -1
    aabs = 10**12
    amax = a[N-1]
    # print(a,amax)
    for i in range(N-1):
        tmp = abs(amax/2 - a[i])
        if tmp < aabs:
            aabs = tmp
            ans = i
    print(a[N-1], a[ans])

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
A = sorted(map(int, input().split()))
diff = float("inf")
ans = 0
for a in A[:-1]:
    d = abs(a - A[-1] / 2)
    if d < diff:
        ans = a
        diff = d
print(A[-1], ans)

Submission status: Accepted

Solution code:

n = int(input())
a = list(map(int, input().split()))
x = max(a)
a.sort()
min = 10 ** 10
del a[-1]
for i in range(n - 1):
    if min > abs(x / 2 - a[i]):
        min = abs(x / 2 - a[i])
        y = a[i]
print(x, y)

Submission status: Accepted

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

a.sort()
m = a[-1] / 2


i = bisect.bisect_left(a[:-1], m)

if i == n-1:
    i -= 1
elif i > 0 and abs(a[i-1]-m) < abs(a[i]-m):
    i -= 1

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
x = a[-1]/2
ans = 0
dis = float("Inf")
for i in range(n-1):
    if dis > abs(x-a[i]):
        ans = a[i]
        dis = abs(x-a[i])
print(a[-1],ans)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
m=max(l)
l.remove(m)
if m%2!=0:
  med=(m+1)//2
else:
  med=m//2
mi=m
for ll in l:
  mi=min(mi,abs(ll-med))
if med+mi in l:
  print(m,med+mi)
else:
  print(m,med-mi)

Submission status: Accepted

Solution code:
import bisect
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
mx = a[-1]

idx = bisect.bisect_left(a, mx//2)
if a[idx] == mx//2:
    print(mx, a[idx], sep=" ")
else:
    if a[idx] == mx:
        print(mx, a[idx-1], sep=" ")
        exit()
    if idx > 0:
        if abs(mx//2 - (mx-a[idx])) > abs(mx//2 - a[idx-1]):
            print(mx, a[idx-1], sep=" ")
        else:
            print(mx, a[idx], sep=" ")
    else:
        print(mx, a[idx], sep=" ")

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    n = A[-1]
    import bisect
    idx = bisect.bisect_left(A, n//2)
    candidates = []
    if idx < N:
        candidates.append(A[idx])
    if idx > 0:
        candidates.append(A[idx-1])

    if abs(n/2 - candidates[0]) < abs(n/2 - candidates[1]):
        print(n, candidates[0])
    else:
        print(n, candidates[1])       

    
if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

A.sort()


ncand = A[-1]

ccand = A[0]
nhalf = ncand // 2
diff = abs(nhalf - ccand)

for i in range(1, N-1):
    d = abs(nhalf - A[i])
    if diff >= d:
        ccand = A[i]
        diff = d

print(ncand, ccand)

Submission status: Accepted

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

N = int(input())
A = sorted(list(map(int, input().split())))[::-1]

h = A[0]/2
r = 10**9
v = 0
for a in A[1:]:
    if r > abs(a-h):
        r = abs(a-h)
        v = a

print(str(A[0]) + ' ' + str(v))

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    A.sort()
    m = A.pop()
    B = [[a, abs(a - (m / 2))] for a in A]
    B.sort(key = lambda x: x[1])
    print('{} {}'. format(m, B[0][0]))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
m = max(a)
b = [abs(i - m / 2) for i in a]
print(m, a[b.index(min(b))])

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
B = A.copy()
A_max = max(A)
ans = 100

for i in range(n):
    if B[i] > A_max // 2:
        B[i] = A_max-B[i]

B.sort()
if B[-1] in A:
    print(str(A_max)+" "+str(B[-1]))
else:
    print(str(A_max)+" "+str(A_max-B[-1]))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 10**18
for i in range(n-1):
    if abs(a[i] - a[-1]/2) < abs(ans - a[-1]/2):
        ans = a[i]
print(a[-1],ans)

Submission status: Accepted

Solution code:
import bisect
import math

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

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

if j == 0 or a - As[j] > As[j-1]:
  print("{} {}".format(a, As[j]))
else:
  print("{} {}".format(a, As[j-1]))

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
M=max(X)
X.remove(M)
m=min([abs(2*x-M) for x in X])
if (M+m)//2 in X:
    m=(M+m)//2
else:
    m=(M-m)//2
print(M,m)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
d = max(a)
f = d
for v in a:
  if abs(v-d/2) < abs(f-d/2):
    f = v
  elif abs(v-d/2) == abs(f-d/2):
    f = min(f,v)
print(d,f)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect

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

# 確定
last = a[-1]
a = a[:-1]

first = 10**10
now = 10**10

for i in a:
    m = min(abs(i-last//2),abs(i-(last+1)//2))
    if now > m:
        now = m
        first = i

print(last,first)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
from collections import defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
A = sorted(A)
MAX = A[-1]
MIN = A[0]
for i in range(1,n-1):
    if abs(MAX/2 - A[i]) <= abs(MAX/2 - MIN):
        MIN = A[i]
print(MAX,MIN)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
M = A[-1]
a = M // 2
for i in range(N-1):
  if A[i] <= a and A[i+1] >= a:
    if (M-A[i])*A[i] >= (M-A[i+1])*A[i+1]:
      ans = [M, A[i]]
    else:
      ans = [M, A[i+1]]
ans = [str(b) for b in ans]
ans = ' '.join(ans)
print(ans)

Submission status: Accepted

Solution code:
import sys
# import io, os
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def main():
    n = int(input())
    a = sorted(list(map(int,input().split())))
    t = 10**10
    if a[-1]%2 == 0:
        for e in a:
            if abs(e-a[-1]//2) < abs(t-a[-1]//2):
                t = e
    else:
        for e in a:
            if abs(e-(1+a[-1])//2) < abs(t-(1+a[-1])//2):
                t = e
    print(a[-1],t)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
n = A[-1]
k = A[0]
for i in range(1,N-1):
    j = A[i]
    if k<=n//2 and j<=n//2:
        k = max(k,j)
    elif k<=n//2 and j>n//2:
        if k<n-j:
            k = j
    elif k>n//2 and j<=n//2:
        if n-k<j:
            k = j
    elif k>n//2 and j>n//2:
        if n-k<n-j:
            k = j
print(n,k)

Submission status: Accepted

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

n = int(input())
a = [int(x) for x in input().split()]
N = max(a)

if N % 2 == 0:
    ans = N // 2
    dis = 10**18
    ans_ = N
    for i in a:
        if abs(i - ans) <= dis:
            dis = abs(i - ans)
            ans_ = i
    print(N, ans_)

else:
    ans1 = N // 2
    ans2 = ans1 + 1
    ans_ = N
    dis = 10**18
    for i in a:
        if abs(i -ans1) <= dis:
            dis = abs(i - ans1)
            ans_ = i
        if abs(i - ans2) <= dis:
            dis = abs(i - ans2)
            ans_ = i
    print(N, ans_)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

from bisect import bisect_left


def combination(n, r): #nCrを求める
    if n - r < r:
        r = n - r
    tmp = 1
    for i in range(n - r + 1, n + 1):
        tmp *= i
    for i in range(1, r + 1):
        tmp //= i
    return tmp



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

a1 = A[-1]
tmp = bisect_left(A, a1 // 2)
b1 = A[tmp]

if tmp != 0:
    if abs(b1 / a1 - 1/2) >= abs(A[tmp - 1] / a1 - 1/2):
        b1 = A[tmp - 1]

print (a1, b1)

Submission status: Accepted

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

a.sort()
left = a.pop()
yoi = left/2
for i in range(n-1):
    if a[i] >= yoi:
        a[i] = (abs(a[i]-yoi), 1)
    else:
        a[i] = (abs(a[i]-yoi), -1)
a.sort()
right = abs(int(a[0][0]+a[0][1]*yoi))
print(left, right)

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    A.sort()
    L = A[N-1]
    ans = -1
    for a in A[:N-1]:
        if abs(L/2 - a) < abs(L/2 - ans): ans = a
    print(L, ans)


    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
x=a[0]
diff=10**9
for i in range(1,n):
  if abs(x-2*a[i])<diff:
    y=a[i]
    diff=abs(x-2*y)
print(x)
print(y)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
x = max(A)
A.pop(A.index(max(A)))
ans = A[0]
ABS = abs(x//2-A[0])
for a in A[1:]:
    if ABS > abs(x//2-a):
        ans = a
        ABS = abs(x//2-a)
print(x,ans)

Submission status: Accepted

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

m = max(a)
res = 1e10
ans = 0
for i in a:
    if i != m:
        if abs(m//2-i) < res:
            res = abs(m//2-i)
            ans = i

print(m,ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
mx = max(A)
A = [a for a in A if a < mx]

A.sort(key=lambda a: abs(mx / 2 - a))
print(mx, A[0])

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans1 = max(A)
if A[1] == 0:
    print(ans1, 0)
for i in range(n):
    if i == 0:
        pass
    elif i == 1:
        ans2 = A[i]
        now_div = abs(ans1/2 - ans2)
    else:
        chk = A[i]
        chk_div = abs(ans1/2 - chk)
        if chk_div > now_div:
            print(ans1, ans2)
            exit()
        if abs(ans1/2 - chk) < abs(ans1/2 - ans2):
            ans2 = chk
            now_div = abs(ans1/2 - ans2)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
ai=a[-1]
aj=a[0]
for j in range(1,n-1):
    if abs(ai/2-a[j]) < abs(ai/2-aj):
        aj=a[j]
print(ai, aj)

Submission status: Accepted

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

m = a[-1]
a_minus_m = [abs(aa-m/2) for aa in a]

mi = 10**10
i_mi=0
for i,aa in enumerate(a_minus_m):
    if aa<mi:
        mi =aa
        i_mi=i

r = a[i_mi]
print(m,r)

Submission status: Accepted

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

a.sort()

large = max(a)
a.remove(large)
min_list = [0, large/2]
for i in a:
    if abs(i - large/2) < min_list[1]:
        min_list = [i, abs(i - large/2)]

print(large, min_list[0])

Submission status: Accepted

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

a.sort()

large = max(a)
a.remove(large)
min_list = [0, large/2]
for i in a:
    if abs(i - large/2) < min_list[1]:
        min_list = [i, abs(i - large/2)]

print(large, min_list[0])

Submission status: Accepted

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
A = sorted(A)
ma = A[-1]
mi = A[0]
for i in range(n-1):
    if abs(A[i] - ma/2) <= abs(mi - ma / 2):
        mi = A[i]
print(ma,mi)

Submission status: Accepted

Solution code:
# D - Binomial Coefficients

import sys
readline = sys.stdin.readline

n = int(readline())
A = list(int(a) for a in readline().split())
A.sort(reverse=True)

N = A[0]
R = 0
tmpR = 0
for i in range(1, n):
    tmp = min(A[i], N-A[i])
    if tmpR < tmp:
        tmpR = tmp
        R = A[i]       

print(N, R)

Submission status: Accepted

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

a.sort()
import bisect
bl = bisect.bisect_left(a, a[-1]//2)
#print(a[-1], a[bl], a[bl-1])

if abs(a[-1]/2 - a[bl]) < abs(a[-1]/2 - a[bl-1]):
    print(a[-1] , a[bl])
else:
    print(a[-1] , a[bl-1])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
maxkouho = a[-1]
k = maxkouho/2
maxans = 10**18
ans = 0
for i in range(n-1):
	s = abs(a[i]-k)
	if s < maxans:
		maxans = s
		ans = a[i]
print(maxkouho, ans)

Submission status: Accepted

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

ansn = max(a)
b = list(map(lambda x: abs(x-ansn/2), a))

minu = 10**9+1
ind = 0

for i in range(n):
  if b[i] <= minu:
    minu = b[i]
    ind = i
    
print(str(ansn)+" "+str(a[ind]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Jun  4 19:55:07 2020

@author: NEC-PCuser
"""

def binary_search(b, a):
    low = 0
    high = len(b) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = b[mid]
        if guess == a:
            return b[mid]
        elif guess > a:
            high = mid - 1
        else:
            low = mid + 1
    abs_low = a * 4
    if len(b) > low: 
        abs_low = abs(b[low] - a)
    abs_high = abs(b[high] - a)
    return b[high] if abs_low > abs_high else b[low]
    
            


if __name__ == "__main__":
    n = int(input())
    
    a = list(map(int, input().split()))
    
    a.sort()
    
    b = a[0:len(a)-1]
    c = binary_search(b, a[len(a)-1] / 2)
    print(str(a[len(a)-1]) + " " + str(c))

Submission status: Accepted

Solution code:
import numpy as np

n = int(input().strip())
A = list(map(int,input().strip().split(' ')))
sorted_A = sorted(A)
ai=sorted_A[-1]
print(ai)
del sorted_A[-1]
tmplist=np.array([min(i,ai-i) for i in sorted_A])
maxidx = np.argmax(tmplist)

print(sorted_A[int(maxidx)])

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
AS = sorted(list(set(A)))
n = AS[-1]
checkAS = len(AS)-1
nHalf = n/2
min = 10**10


for i in range(checkAS):
    temp = abs(AS[i]-nHalf)
    if min > temp:
        r = AS[i]
        min = temp

print(str(n) + ' ' + str(r))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
A = map(int, input().split())
A = sorted(A)
maxa = max(A)

from bisect import bisect_left
m = (maxa+1)//2
l2 = bisect_left(A, m)

if abs(A[l2] - m) >= abs(A[l2-1] - m):
    print(maxa, A[l2-1])
else:
    print(maxa, A[l2])

Submission status: Accepted

Solution code:
from math import ceil
n = int(input())
data = list(map(int, input().split()))
n = max(data)
nn = n/2.0
r = min((d for d in data if d != n), key=lambda x: abs(nn-x))
print(n, r)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
m1 = A[-1]
m2 = m1 // 2 + int(m1 % 2 == 1)
ans = [m1, 0]
tmp = 10**9 + 1

for a in A[:len(A) - 1]:
    if tmp > abs(m2 - a):
        tmp = abs(m2 - a)
        ans[1] = a

print(*ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from bisect import bisect_left, bisect_right


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def solve(N, A):
    A.sort()
    n = N-1
    p = bisect_left(A, A[n] / 2)
    low = max(0, p - 1)
    high = min(N - 1, p)
    if n == high:
        return "%d %d" % (A[n], A[low])
    elif A[low] > A[n] - A[high]:
        return "%d %d" % (A[n], A[low])
    else:
        return "%d %d" % (A[n], A[high])


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
A.sort()
y = max(A)
x = A[0]
for a in A:
    if abs(y/2-a) < abs(y/2 - x):
        x = a
print(y, x)

Submission status: Accepted

Solution code:
n = int(input())
dat = list(map(int, input().split()))
dat.sort()
x = dat[-1]
xx = x / 2
dat = dat[:-1]
mindiff = 999999999999999999999999999
minnum = None
for i in range(n-1):
    if abs(xx-dat[i]) < mindiff:
        mindiff = abs(xx-dat[i])
        minnum = dat[i]
print(x, minnum)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

n = INT()
a = LIST()

p = max(a)
m = (p+1)/2 - 0.1
b = []
a.remove(p)
for x in a:
	b.append((x, abs(x-m)))

b.sort(key = lambda x:x[1])

print(p, b[0][0])

Submission status: Accepted

Solution code:
import bisect

N = int(input())
a = set(map(int,input().split()))
A = sorted(list(a))
M = max(A)
num = M//2

index = bisect.bisect_right(A,num)

if index > 0 and abs(num - A[index]) > abs(num - A[index-1]):
    index = index-1
#print(index)

if M != A[index]:
    print(M,A[index])
else:
    print(M,A[index-1])

Submission status: Accepted

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
a_list.sort()
a_max = a_list.pop()
result = []
import math
for a in a_list:
  result.append(abs(math.ceil(a_max /2) - a))

print(a_max,a_list[result.index(min(result))])

Submission status: Accepted

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

ans1 = a[-1]
ans2 = 0

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

Submission status: Accepted

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

big = arr.max()
arr = np.delete(arr, arr.argmax())

if big % 2 == 0:
    small = arr[(np.abs(arr - big // 2)).argmin()]
else:
    a = (np.abs(arr - (big + 1) // 2)).min()
    b = (np.abs(arr - (big) // 2)).min()
    if a <= b:
        small = arr[(np.abs(arr - (big + 1) // 2)).argmin()]
    else:
        small = arr[(np.abs(arr - big // 2)).argmin()]

print(big, small)

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))

    a.sort()
    a_max=a[-1]
    b_max=-1
    for i in range(n-1):
        if b_max<min(a[i],a_max-a[i]):
            b_max=a[i]

    print(a_max,b_max)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
x = a[-1]
y1 = x//2
y2 = x//2 + 1
sa1, sa2 = float("inf"), float("inf")
z1, z2 = 0, 0
for i in range(n-1):
    if sa1 > abs(y1 - a[i]):
        sa1 = abs(y1-a[i])
        z1 = a[i]
    if sa2 > abs(y2 - a[i]):
        sa2 = abs(y2 - a[i])
        z2 = a[i]

if sa1 > sa2:
    print(x, z2)
else:
    print(x, z1)

Submission status: Accepted

Solution code:
import bisect

n,*a = map(int, open(0).read().split())
if n == 2:
    print(*a)
else:
    a.sort()
    f = a[-1]
    h = f / 2
    bs = bisect.bisect_left(a,h)
    if abs(a[bs-1]-h) >= abs(a[bs]-h):
        s = a[bs]
    else:
        s = a[bs-1]
    print(f,s)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
p=max(a)
r=p/2
print(p,int(min([i-r for i in a if i!=p],key=abs)+r))

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
A = IL()

A.sort()

n = A.pop()

MIN = (INF,INF)
for a in A:
  if MIN[0] > (abs(n/2-a)):
    MIN = (abs(n/2-a),a)
  
print(n,MIN[1])

Submission status: Accepted

Solution code:
import bisect

n,*a = map(int, open(0).read().split())
if n == 2:
    print(*a)
else:
    a.sort()
    f = a[-1]
    h = f / 2
    bs = bisect.bisect_left(a,h)
    if abs(a[bs-1]-h) >= abs(a[bs]-h):
        s = a[bs]
    else:
        s = a[bs-1]
    print(f,s)

Submission status: Accepted

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

def binary(l,i):
  r=N-1
  while l<=r:
    m=(l+r)//2
    if A[m]==i:
      return A[m]
    elif A[m]>i:
      r=m-1
    else:
      l=m+1
  x=abs(A[m]-i)
  for j in range(max(0,m-2),min(m+3,N-1)):
    if x >= abs(A[j]-i):
      res = A[j]     
      x=abs(A[j]-i)
  return res


print(A[-1],binary(1,A[-1]/2))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    aj = A.pop()
    A.sort(key=lambda x: abs(aj / 2 - x))
    print(aj, A[0]) 
main()

Submission status: Accepted

Solution code:
_, *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:
import bisect
import math
n = int(input())
l = sorted(list(map(int,input().split())))
if len(l)==2 :
  print(l[-1],l[-2])
  exit()
  
a = l[-1]/2
s = bisect.bisect_left(l,a)
if l[s]==a:
  print(l[-1],l[s])
  exit()
k1 = l[s-1]
k2 = l[s]
s1 = a-k1
if k2==l[-1]:
  k2 = k1
s2 = abs(k2-a)
#print(s,k1,k2,s1,s2)
if s1<=s2:
  print(l[-1],k1)
else:
  print(l[-1],k2)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
n = max(a)
tmp = n / 2
r = n + 1
d = n + 1
for num in a:
    if num == n:
        continue
    d_tmp = abs(num - tmp)
    if d_tmp < d:
        d = d_tmp
        r = num
print(n, r)

Submission status: Accepted

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    def combinations_count(n, r):
        if n > 1:
            return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
        else:
            return 0

    n = ni()
    a = na()

    a.sort()

    max_ai = max(a)
    idx = bisect.bisect_left(a, max_ai // 2)

    r = -1

    r = a[max(0, idx - 1)]
    if a[idx] != max_ai:
        r = a[idx] if abs(a[idx] - max_ai / 2) < abs(r - max_ai / 2) else r

    print(max_ai, r)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

A.sort()

m = A[-1]
M = [abs((m / 2) - a) for a in A[: -1]]
r = A[M.index(min(M))]

print(m, r)

Submission status: Accepted

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

A.sort()

m = A[-1]
M = [abs((m / 2) - a) for a in A[: -1]]
r = A[M.index(min(M))]

print(m, r)

Submission status: Accepted

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