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

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)


###############################################################################


def main():
    n = intin()
    alist = intina()

    alist.sort()

    m = alist[-1]

    ind = binl(alist, m // 2)
    ind1 = ind - 1 if ind > 0 else None
    ind2 = ind

    mmlist = [m // 2]
    if m & 1:
        mmlist.append(m // 2 + 1)

    c1 = float('inf')
    if ind1 is not None and ind1 != len(alist) - 1:
        for mm in mmlist:
            c1 = min(c1, abs(alist[ind1] - mm))

    c2 = float('inf')
    if ind2 != len(alist) - 1:
        for mm in mmlist:
            c2 = min(c2, abs(alist[ind2] - mm))

    if c1 < c2:
        print('%d %d' % (m, alist[ind1]))
    else:
        print('%d %d' % (m, alist[ind2]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# sys.stdin.readline()
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
ans_1 = max(a)
check_2 = ans_1 / 2
a.sort()
ans_box = [0]*n
for i in range(n):
    ans_box[i] = abs(a[i]-check_2)
ans_2 = a[ans_box.index(min(ans_box))]
print(ans_1,ans_2)

Submission status: Accepted

Solution code:
#ABC094-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
A=IL()
A.sort()
ai=A[-1]
tA=A[:n-1]
aj=0
for i in range(n-1):
    aj=max(aj,min(tA[i],ai-tA[i]))
if aj in tA:
    print(ai,aj)
else:
    print(ai,ai-aj)

Submission status: Accepted

Solution code:

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

tmp = 10 ** 9
ans = 1
for i in range(1,N):
  if abs(a[0]/2 - a[i]) < tmp:
    tmp = abs(a[0]/2 - a[i])
    ans = a[i]

    
s = str(a[0]) + " " + str(ans)
print(s)

Submission status: Accepted

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


if N == 2:
    print(A[-1], A[0])
    quit()

a_i = A[-1]
a_j = bisect.bisect_left(A, a_i//2)
if a_j == 0:
    print(A[-1], A[0])
else:
    a_j1, a_j2 = A[a_j-1], A[a_j]
    if abs(a_i/2 - a_j1) < abs(a_i/2 - a_j2):
        print(a_i, a_j1)
    else:
        print(a_i, a_j2)

Submission status: Accepted

Solution code:
n=int(input())
A=[int(i) for i in input().split()]
if A==[100,0]:print(100,0)
else:
    Ai=max(A)
    Aj=0
    curdif=10000000000000000
    for a in A:
        if abs(Ai/2-a)<curdif:
            Aj=a
            curdif=abs(Ai/2-a)
    print(Ai,Aj)

Submission status: Accepted

Solution code:
import bisect
n=int(input())
A=[int(i) for i in input().split()]
A.sort()
l=A[-1]
A=A[:-1]
n=bisect.bisect_left(A,l//2)
if n==len(A):
  s=A[-1]
else:
  s=A[n]
if n>1 and abs(A[n-1]-l/2)<abs(A[n]-l/2):
  s=A[n-1]
print(l,s)

Submission status: Accepted

Solution code:

import bisect





def main():
    num = int(input())
    data = list(map(int, input().split()))
    data.sort()

    ans = 0
    ans_list = []

    for i in range(num - 1, num):
        left_ind = max(bisect.bisect_left(data, data[i] // 2) - 1, 0)
        if left_ind + 1 >= i:
            right_ind = left_ind
        else:
            right_ind = left_ind + 1

        ans_kari_1 = min(data[left_ind], data[i] - data[left_ind])
        ans_kari_2 = min(data[right_ind], data[i] - data[right_ind])


        if ans_kari_1 > ans_kari_2:
            ans_list = [data[i], data[left_ind]]
        else:
            ans_list = [data[i], data[right_ind]]

    print(ans_list[0], ans_list[1])






if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#coding:utf-8
N=input()
A=map(int,raw_input().split())
A.sort()
n=A[-1]
med=n/2
p=0
mi=1145141919810
for i,a in enumerate(A):
    b=min(a,n-a)
    if abs(b-med) < mi:
        p=i; mi=abs(b-med)
print("%d %d"%(n,A[p]))

Submission status: Accepted

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

q = max(A)
p = q//2
tmp = p+1
for i in range(N):
    if q != A[i]:
        if tmp > abs(A[i]-p):
            tmp = abs(A[i]-p)
            ans = A[i]

print(q, ans)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
m=max(l)
del l[l.index(m)]
m1=l[0]
for i in l:
  if abs(m/2-i)<abs(m1-m/2):
    m1=i
print(m,m1)

Submission status: Accepted

Solution code:
n = int(input())
As = list(map(int, input().split()))
As.sort()
a1 = As[-1]
a2 = 0
a3 = As[-1]
m = a1//2
for a in As:
    if a > a2 and a <=m:
        a2 = a
    elif a < a3 and m < a:
        a3 = a
if m % 2 == 0:
    if abs(a2-m) <= abs(a3-m):
        print(a1, a2)
    else:
        print(a1, a3)
else:
    if abs(a2-m) <= abs(a3-m-1):
        print(a1, a2)
    else:
        print(a1, a3)

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
A.sort()
max_a = A[-1]
print(max_a, min(A, key=lambda a:abs(max_a-a*2)))

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
mx=max(l)
rmx=0
for i in l:
  x=min(i,mx-i)
  if rmx<x:
    rmx=x
if l.count(rmx)>0:
  print(mx,rmx)
else:
  print(mx,mx-rmx)

Submission status: Accepted

Solution code:
from bisect import bisect_left
N=int(input())
inp=[int(i)for i in input().split()]
inp.sort()
ma=inp[-1]
idx = bisect_left(inp[0:-1], ma//2)
if idx >= len(inp)-1:
    if idx >= len(inp)-1:
        print(ma, inp[idx-1])
    else:
        print(ma, inp[idx])
elif abs(inp[idx] - ma//2) < abs(ma//2 - inp[idx - 1]) or abs(ma - inp[idx] - ma//2) < abs(ma//2 - inp[idx - 1]):
    print(ma, inp[idx])
else:
    print(ma, inp[idx-1])

Submission status: Accepted

Solution code:
from bisect import bisect_left
N=int(input())
inp=[int(i)for i in input().split()]
inp.sort()
ma=inp[-1]
idx = bisect_left(inp[0:-1], ma//2)
# print(inp, inp[idx], ma//2)
if idx >= len(inp)-1:
    # print("d1", inp[idx], inp[idx + 1])
    if idx >= len(inp)-1:
        print(ma, inp[idx-1])
    else:
        print(ma, inp[idx])
elif abs(inp[idx] - ma//2) < abs(ma//2 - inp[idx - 1]) or abs(ma - inp[idx] - ma//2) < abs(ma//2 - inp[idx - 1]):
    # print("d2", inp[idx], inp[idx-1])
    print(ma, inp[idx])
else:
    # print("d3", inp[idx], inp[idx-1])
    print(ma, inp[idx-1])

Submission status: Accepted

Solution code:
import bisect
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
from operator import mul

import numpy as np
import re
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

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

# nCr を求める
# r が同じなら、n は大きいほうが nCr は大きい
n = A[-1]
# n が同じなら、r は n / 2 に近いほど大きい
r = bisect.bisect_left(A, n / 2)

if abs(A[r - 1] - n / 2) < abs(A[r] - n / 2):
    r -= 1
while A[r] == n:
    r -= 1
print(n, A[r])

Submission status: Accepted

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

c = a[-1]
d = max(a[:-1], key=lambda x: min(x, c - x))

print(c, d)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans1 = max(a)
a.remove(ans1)
ans2 = a[0]
t = ans1 // 2
for i in range(n - 1):
    if abs(t - ans2) > abs(t - a[i]):
        ans2 = a[i]
print(ans1, ans2)

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
A.sort()
ai=A[-1]
A=A[:-1]
ans=10**19
aj=0
if ai%2==0:
    a=ai//2
    for i in range(n-1):
        if ans>abs(A[i]-a):
            ans=abs(A[i]-a)
            aj=A[i]
    print(ai,aj)
else:
    a=(ai-1)//2
    b=a+1
    for i in range(n-1):
        if ans>min(abs(A[i]-a),abs(A[i]-b)):
            ans=min(abs(A[i]-a),abs(A[i]-b))
            aj=A[i]
    print(ai,aj)

Submission status: Accepted

Solution code:
import sys
import math
import numpy as np
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()
N = ni()
A = na()
A.sort()
n = A[-1]
m = n*1.0/2
#print(m)
inf = 10**9
ans=0
for i in range(N):
    if(abs(A[i]-m)<inf):
        inf= abs(A[i]-m)
        ans = A[i]
print(n,ans)

Submission status: Accepted

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

A.sort(reverse = True)

x = A[0]
y = 0
temp = 0

for yy in A:
    d = min(yy, x-yy) # dが大きいと良い
    if d > temp:
        temp = d
        y = yy

ans = (x,y)
print(*ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int, input().split()))
b=max(a)
_,c=min([(abs(b/2-x), x) for x in a])
print("%d %d" % (b, c))

Submission status: Accepted

Solution code:
from operator import itemgetter

n = int(input())
a = sorted(list(map(int, input().split())))
max_n = a.pop(-1)
x = max_n / 2
a_ = sorted([(x, abs(max_n/2-x)) for x in a], key=itemgetter(1))

print(max_n, a_[0][0])

Submission status: Accepted

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

Submission status: Accepted

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

b = sorted(a,reverse=True)

def binary_search(x):
    l,r = 0,n-1
    while l+1<r:
        i = (l+r)//2
        if b[i] > x:
            l = i
        else:
            r = i
    if abs(b[l]-x)>=abs(b[l+1]-x):
        l += 1
    return b[l]

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

ans = ""
m = 0
for c in b[:1]:
    r = binary_search(c/2)
    #comb_c_r = comb(c,r)
    #if m < comb_c_r:
        #m = comb_c_r
    ans = str(c)+" "+str(r)
print(ans)

Submission status: Accepted

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

a.sort()

ai = a[-1]

aj = a[0]
for i in a[:-1]:
    if abs(ai//2 + ai % 2- aj) > abs(ai//2 + ai % 2 - i):
        aj = i

print(ai, aj)

Submission status: Accepted

Solution code:
import sys


fin = sys.stdin.readline
n = int(fin())
a_list = sorted(int(elem) for elem in fin().split())

num_elems = a_list[-1]
num_choices = -1
max_diff = float('-inf')
for a in a_list[:-1]:
    diff = min(num_elems - a, a)
    if diff > max_diff:
        num_choices = a
        max_diff = diff

print(num_elems, num_choices)

Submission status: Accepted

Solution code:
import bisect

N=int(input())
a=list(map(int,input().split()))
b=sorted(a)
M=b[N-1]
i=bisect.bisect_left(b,M/2)

if i==0: print(M,b[0])
elif abs(M/2-b[i-1])<=abs(M/2-b[i]): print(M,b[i-1])
else: print(M,b[i])

Submission status: Accepted

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


def solve(n: int, a: "List[int]"):
    a.sort()
    n = a[-1]
    a = a[0:len(a)-1]
    maxDiff = 0
    maxK = a[0]
    for k in a:
        if maxDiff <= min(n-k, k):
            maxDiff = min(n-k, k)
            maxK = k
    print(str(n) + " " + str(maxK))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    solve(n, a)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

a = max(A)
A.remove(a)
A.sort(key=lambda x:abs(x-a/2))
b = A[0]
print(' '.join([str(a), str(b)]))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
A = max(a)
t = -1
tt = 0
for i in range(n):
    if t < a[i]:
        t = a[i]
        tt = i
a.pop(tt)
# print(a)
z = A / 2
d = float('INF')
da = 0
for i in range(n - 1):
    # print(d, abs(a[i] - z))
    if d > abs(a[i] - z):
        da = a[i]
        d = abs(da - z)
print(A, da)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
aj = max(A)
temp = 10000000000
for a in A:
    if a != aj:
        if temp > abs(int(aj/2+0.5)-a):
            ai = a
            temp = abs(int(aj/2+0.5)-a)
            
print(aj,ai)

Submission status: Accepted

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

ans1 = a[0]
dif = 1e10
for i in a:
    if i==ans1:
        continue
    if abs(i-ans1//2)<dif:
        ans2 = i
        dif = abs(i-ans1//2)

print(ans1, ans2)

Submission status: Accepted

Solution code:
n = int(input())
A = sorted(list(map(int,input().split())),reverse=True)
k = 10**10
for i in range(1,n):
    k = min(k,abs(A[0]/2 -A[i]))
    if k == abs(A[0]/2 -A[i]):
        ans = [A[0],A[i]]
print(ans[0],ans[1])

Submission status: Accepted

Solution code:
N = int(input())
lst = sorted(list(map(int, input().split())), reverse=True)

max_comb = -1
k = lst[0]
mid = k/2
high = 1
low = N-1
while abs(high - low) > 1:
    if mid - lst[(high+low)//2] ==0:
        high = (high+low) // 2
        low = high
        break
    elif mid - lst[(high+low)//2] > 0:
        low = (high+low)//2
    else:
        high = (high+low)//2
p = lst[high] if abs(mid - lst[high]) < abs(mid - lst[low]) else lst[low]
print(k, p)

Submission status: Accepted

Solution code:
import bisect
N=int(input())
A=[int(x) for x in input().split()]
A.sort()
At=A[-1]
i=bisect.bisect_left(A,At/2)
if i==0:
  As=A[i]
elif i==N-1:
  As=A[i-1]
else:
  As=A[i] if A[i]-At/2<At/2-A[i-1] else A[i-1]
print(At,As)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a_ = sorted(a)
if len(a)==2:
    print(a_[1],a_[0])
    exit()
a = a_[::-1]
k = 10**9
for i in range(1,n):
    if k>abs(a[0]/2-a[i]):
        k=abs(a[0]/2-a[i])
        ans = [a[0],a[i]]
print(ans[0],ans[1])

Submission status: Accepted

Solution code:
import bisect
import math

n = int(input())
a = [int(item) for item in input().split()]
a.sort()
ai = a[-1]

left = bisect.bisect(a, ai/2) - 1
right = left + 1

if a[right] - ai/2 >= ai/2 - a[left]:
  print(ai, a[left])
else:
  print(ai, a[right])

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


#A
def A():
    a,b = LI()
    if not (a*b)%2:
        print("Even")
    else:
        print("Odd")
    return

#B
def B():
    s = S()
    print(s.count("1"))
    return

#C
def C():
    n = I()
    a = LI()
    f = 0
    for j in range(100000):
        for i in range(n):
            if a[i]%2:
                f = 1
                break
            a[i] //= 2
        if f:break
    print(j)
    return

#D
def D():
    a,b,c,x = IR(4)
    su = 0
    for i in range(a+1):
        for j in range(b+1):
            for k in range(c+1):
                if 500*i+100*j+50*k == x:su += 1
    print(su)
    return

#E
def E():
    n,y = LI()
    for i in range(n+1):
        for j in range(n+1-i):
            k = n-i-j
            if 10000*i+5000*j+1000*k == y:
                print(i,j,k)
                quit()
    print(-1,-1,-1)
    return

#F
def F():
    s = input()
    while s:
        if s[:11] == "dreameraser":
            s = s[11:]
        elif s[:10] == "dreamerase":
            s = s[10:]
        elif s[:7] == "dreamer":
            s = s[7:]
        elif s[:6] == "eraser":
            s = s[6:]
        elif s[:5] == "dream":
            s = s[5:]
        elif s[:5] == "erase":
            s = s[5:]
        else:
            print("NO")
            quit()
    print("YES")
    return

#G
def G():
    n,a,b = LI()
    h = IR(n)
    return

#H
def H():
    n = I()
    a = LI()
    a.sort()
    m = a[-1]
    i = bisect.bisect_left(a,m//2)
    b = float("inf")
    c = float("inf")
    if i > 0:
        k = a[i-1]
        l = m-a[i-1]
        b = max(k,l)-min(k,l)
    if i < n-1:
        d = a[i]
        l = m-a[i]
        c = max(d,l)-min(d,l)
    if b < c:
        print(m,k)
    else:
        print(m,d)
    return

#Solve
if __name__ == "__main__":
    H()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
largest = a[-1]
aim = largest // 2
index = 0
for i in range(n):
    if a[i] >= aim:
        index = i
        break
if a[index] - aim <= aim - a[index-1] and index < n-1 :
    ans = a[index]
else:
    ans = a[index-1]
print(str(largest) + " " + str(ans))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split(" ")]
m = max(a)
abs_min = m
abs_i = 0

for i in range(0, n):
    ab = abs((m + 1)//2 - a[i])
    if a[i] != m and abs_min > ab:
        abs_min = ab
        abs_i = i
        
print(m, a[abs_i])

Submission status: Accepted

Solution code:
input();a=sorted(list(map(int,input().split())));print(a[-1],sorted(a,key=lambda x:abs(a[-1]-2*x))[0])

Submission status: Accepted

Solution code:
import bisect

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

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

M = max(a)
m = M/2
mid = bisect.bisect_left(a, m)
x, y = abs(a[mid-1] - m), abs(a[mid] - m)

if x < y:
    print(M, a[mid-1])
else:
    print(M, a[mid])

Submission status: Accepted

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

ans = 0
diff = 0
for i in range(N):
    x = min(A[-1] - A[i], A[i])
    if x > diff:
        diff = x
        ans = A[i]
        
print(A[-1], ans)

Submission status: Accepted

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

l.sort()
N = l[-1]
if N%2:
    M_L = N//2
    M_R = N//2+1
else:
    M_L = N//2
    M_R = N//2
max_idx = 0
min_dis = N+1

for i in range(n-1):
    if min(abs(l[i]-M_L),abs(l[i]-M_R)) < min_dis:
        max_idx = i
        min_dis = min(abs(l[i]-M_L),abs(l[i]-M_R))
print(str(N)+" "+str(l[max_idx]))

Submission status: Accepted

Solution code:
import copy

n=int(input())
a=list(map(int,input().split()))
ma=max(a)
a2=copy.copy(a)
a2.remove(ma)
ma2 = ma/2
a3 = [(abs(v-ma2),v) for v in a2]
print(ma,min(a3)[1])

Submission status: Accepted

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

m = max(Ai)
idx = Ai.index(m)
del Ai[idx]

target = m // 2
nearest = 1000000000
use_value = -1
for a in Ai:
    d = abs(a - target)
    if nearest > d:
        nearest = d
        use_value = a

print(m, use_value)

Submission status: Accepted

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
import sys
import itertools as itr


input()
An = list(map(int, sys.stdin.readline().rstrip().split()))

n = max(An)
r = 0
for a in An:
  if a == n:
    continue

  if abs(2*a-n) < abs(2*r-n):
    r = a
print(n,r)

Submission status: Accepted

Solution code:
c = int(input())
l = list(map(int, input().split()))
n = max(l)
r = 0
for i in l:
  if abs(n/2 - i) < abs(n/2 - r):
    r = i
from math import factorial
print(n,r)

Submission status: Accepted

Solution code:
import bisect as bs
l=int(input())
lst=sorted(list(map(int,input().split())))
n=lst[l-1]
lst[l-1]=float("inf")
m=bs.bisect_right(lst,n/2)
if n/2 - lst[m-1] <= lst[m] -n/2:
  print(n,lst[m-1])
else:
  print(n,lst[m])

Submission status: Accepted

Solution code:
a = int(input())
x = list(map(float, input().split()))
m = max(x)
M = m/2
t = 0
s = float("INF")
for i in x:
    #print(s,abs(M-i),i,M)
    if s >= abs(M-i):
        s = min(s,abs(M-i))
        t = i
print(str(int(m))+" "+str(int(t)))

Submission status: Accepted

Solution code:
def binomial_coefficients(n: int, A: list) -> tuple:
    max_A = max(A)
    max_r, max_a = 0, 0
    for a in A:
        if a == max_A:
            continue
        r = min(a, max_A - a)
        if max_r < r:
            max_r = r
            max_a = a

    return max_A, max_a


if __name__ == "__main__":
    n = int(input())
    A = list(map(int, input().split()))
    ai, aj = binomial_coefficients(n, A)
    print(ai, aj)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = max(a)
ans = ' '.join((
    str(m),
    str(max(sorted(a), key=lambda x: min(x, m - x)))
))
print(ans)

Submission status: Accepted

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

n=ri()
a=rl()
a.sort()


import bisect

p = a[-1]
p2 = p/2
q_i = bisect.bisect_left(a,p2)
if ((a[q_i]-p2) > (p2 - a[q_i-1]) or p==a[q_i]) and q_i != 0:
    q_i -= 1
q = a[q_i]

print(p,q)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    n = max(A)
    tmp = float("inf")
    r = 0
    for x in A:
        if abs(n-x*2) < tmp and x != n:
            tmp = abs(n-x*2)
            r = x
    print(n, r)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc094/tasks/arc095_b

import itertools
import collections
import bisect

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    n = A[-1]
    pos = bisect.bisect(A, n//2)
    if n == A[pos]:
        r = A[pos-1]
    elif pos == 0:
        r = A[pos]
    else:
        r = A[pos] if abs(n/2-A[pos]) < abs(n/2-A[pos-1]) else A[pos-1]

    print("{} {}".format(n, r))


if __name__ == '__main__':
    main()

Submission status: Accepted

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


ans_n = max(A)
A.remove(ans_n)

ans_r = -1
diff_min = float('inf')

for a in A:
    diff = abs(ans_n / 2 - a)
    if diff < diff_min:
        diff_min = diff
        ans_r = a

print(ans_n, ans_r)

Submission status: Accepted

Solution code:
import sys
from math import factorial

def comb(a, b):
  return factorial(a) / (factorial(b) * factorial(a-b))


def f(A, a):
  if len(A) == 1:
    return A[0]
  
  if len(A) == 2:
    b1, b2 = A[0], A[1]
    if min(b1, a-b1) >= min(b2, a-b2):
      return b1
    else:
      return b2
  
  m = len(A) // 2
  b1, b2, b3 = A[m-1], A[m], A[m+1]
  c1, c2, c3 = min(b1, a-b1), min(b2, a-b2), min(b3, a-b3)
  c = max(c1, c2, c3)  
  
  if c2 == c:
    return b2
  elif c1 == c:
    return f(A[:m], a)
  else:
    return f(A[m+1:], a)


def main():
  input = sys.stdin.readline
  N = int(input())
  A = list(map(int, input().split()))
  A = sorted(A)
  ai = A[-1]
  A = A[:-1]
  aj = f(A, ai)
  print(ai, aj)


if __name__ == '__main__':
  main()

Submission status: Accepted

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

L.sort()
res1 = L[-1]

tmp = res1 / 2

res2 = 10 ** 10
for i in range(N-1):
    if abs(tmp - L[i]) < abs(tmp - res2):
        res2 = L[i]

    
print(res1, res2)

Submission status: Accepted

Solution code:
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
n = A[-1]
x = bisect.bisect_left(A, n / 2)
if x == 0:
    print(n, A[0])
elif x == N:
    print(n, A[-1])
else:
    if n / 2 - A[x - 1] <= A[x] - n / 2:
        print(n, A[x - 1])
    else:
        print(n, A[x])

Submission status: Accepted

Solution code:
import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()
inf = 10 ** 10
m = a[n-1]
a = [-inf] + a[0:n-1] + [inf]
left = bisect.bisect_left(a, m//2)
if m//2 - a[left-1] < a[left] - m//2:
    print(m, a[left-1])
else:
    print(m, a[left])

Submission status: Accepted

Solution code:
import math
import bisect

N = int(input())

A = sorted([int(n) for n in input().split()])

mINF = -1e18
INF = 1e18

mx = A[-1]
A = [mINF] + A[:-1] + [INF]
idx = bisect.bisect_left(A, (mx+1) // 2)

ans = A[idx] if A[idx] - (mx+1) // 2 < (mx+1) // 2 - A[idx-1] else A[idx - 1]

print(mx, ans)

Submission status: Accepted

Solution code:
import bisect as bi

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

A.sort()

n=A[nn-1]

ki=bi.bisect_right(A[:nn-1],float(n/2))
#print(ki)
if abs(float(n/2)-A[:nn-1][min(ki,nn-2)]) <= abs(float(n/2)-A[:nn-1][max(ki-1,0)]) :
    k=A[min(ki,nn-2)]
else :
    k=A[max(ki-1,0)]

print("{} {}".format(n,k))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = []
c = max(a)
d = -100
for i in range(n):

    if a[i] != c:

        if d == -100:

            d = abs((c/2)-a[i])
            e = i 

        else:

            if abs((c/2)-a[i]) < d:

                d = abs((c/2)-a[i]) 
                e = i 
        
        
print('{} {}'.format(c,a[e]))

Submission status: Accepted

Solution code:
# D

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

ans_a = max(a)
min_b = max(a)
for i in range(n):
    if a[i] != ans_a:
        if min_b > abs(a[i] - ans_a/2):
            ans_b = a[i]
            min_b = abs(a[i] - ans_a/2)
print("{} {}".format(ans_a, ans_b))

Submission status: Accepted

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

Submission status: Accepted

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

b = bisect.bisect(a,ma//2)
koho = []
if b-1 >= 0:
    koho.append([abs(ma//2-a[b-1]),a[b-1]])
if b < n-1:
    koho.append([abs(ma//2-a[b]),a[b]])

if ma % 2 == 1:
    b2 = bisect.bisect(a,ma//2+1)
    if b2-1 >= 0:
        koho.append([abs(ma//2+1-a[b2-1]),a[b2-1]])
    if b2 < n-1:
        koho.append([abs(ma//2+1-a[b2]),a[b2]])

koho.sort()
print(ma,koho[0][1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort()
k = 0
j = 0
v = L[N-1]
if N % 2 == 0:
  if L[0]-v/2 >= 0:
    k = L[0]
  elif L[N-1]-v/2 <= 0:
    k = L[N-1]
  else:
    for i in range(N):
      if L[i] >= v/2:
        j = i
        break
    if L[j] == v/2:
      k = L[j]
    else:
      if abs(v/2-L[j-1]) <= abs(v/2-L[j]):
        k = L[j-1]
      else:
        k = L[j]
else:
  if L[0]-(v+1)/2 >= 0:
    k = L[0]
  elif L[N-1]-(v+1)/2 <= 0:
    k = L[N-1]
  else:
    for i in range(N):
      if L[i] >= (v+1)/2:
        j = i
        break
    if L[j] == (v+1)/2:
      k = L[j]
    else:
      if abs((v+1)/2-L[j-1]) <= abs((v+1)/2-L[j]):
        k = L[j-1]
      else:
        k = L[j]
print(v,k)