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:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

##### 割り算の切り上げ #####
# tmp = -(-4 // 3)

##### dict の for文 #####
# for k, v in d.items():
#     print(k, v)

##### 進数の変換 #####
# bin_str = bin(i)[2:]
# oct_str = oct(i)
# hex_str = hex(i)

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()
	A = inputList()
	A.sort()
	AA = A[::-1]

	ans1 = AA[0]
	ans2 = AA[-1]
	ki = ans1 / 2

	for i in AA:
		if i == ans1:
			continue
		if abs(i-ki) < abs(ans2-ki):
			ans2 = i

	print("{} {}".format(ans1,ans2))



#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# 2分検索のリバース
def bisect_left_reverse(a, x):
    if a[0] <= x:
        return 0
    if x < a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] <= x:
            ok = mid
        else:
            ng = mid
    return ok

def bisect_right_reverse(a, x):
    if a[0] < x:
        return 0
    if x <= a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# 2分検索
# 存在しない場合: None 存在する場合: その値
def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1
    return None

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# N 個のボールを K グループに分ける場合のパターン数
def sunuke(N, K, mod=10**9+7):
	if N < K or K-1 < 0:
		return 0
	else:
		return combination(N-1, K-1, mod)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# dfs のサンプル
def dfs(graph,parent,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
import math
import bisect
from queue import Queue
from collections import deque

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

a.sort()

b = a[n-1]
c = bisect.bisect_left(a,b//2)
d = max(c-1,0)

if(abs(b/2 - a[c]) < abs(b/2 - a[d])):
    print(b,a[c])
else:
    print(b,a[d])

Submission status: Accepted

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

mid = (lis[-1] + 1) // 2
p = bisect.bisect_left(lis, mid)
x = abs(lis[p] - mid)
y = abs(lis[p-1] - mid)

if x >= y:
    print(lis[-1], lis[p-1])
else:
    print(lis[-1], lis[p])

Submission status: Accepted

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

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    L = lmi()
    L.sort()
    a = L[-1]
    b = -1
    min_diff_between_half_a = inf
    for elm in L:
        if min_diff_between_half_a > abs(elm - a/2):
            min_diff_between_half_a = abs(elm - a/2)
            b = elm
    print("{} {}".format(a, b))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import bisect

N = 5
ARR = [6, 9, 4, 2, 11]


N = 2
ARR = [100, 0]

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


def calculate(n, arr):
    arr = sorted(arr)

    mid = arr[n - 1] / 2

    a1 = bisect.bisect_left(arr, mid)

    s1 = abs(arr[a1 - 1] - (arr[n - 1] / 2))
    s2 = abs(arr[a1] - (arr[n - 1] / 2))

    if s1 > s2:
        return arr[n - 1],arr[a1]
    else:
        return arr[n-1],arr[a1-1]


n, a = calculate(N, ARR)
print(n, a)

Submission status: Accepted

Solution code:
from bisect import bisect_left
n = int(input())
a_list = sorted([int(x) for x in input().split()])
base = a_list[-1] / 2
i = bisect_left(a_list, base)
if i > 0:
    i -= 1
ans = [a_list[-1], a_list[i], abs(a_list[i] - base)]
for i in range(i + 1, n):
    temp = abs(a_list[i] - base)
    if temp >= ans[2]:
        break
    ans[1] = a_list[i]
    ans[2] = temp
print(ans[0], ans[1])

Submission status: Accepted

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

a.sort()
mx = a[-1]

half = mx / 2
dist = abs(half - a[0])
ans = 0
for i in range(1,n):
    if dist > abs(half - a[i]):
        dist = min(dist,abs(half - a[i]))
        ans = a[i]
print(mx,ans)

Submission status: Accepted

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

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

print(m,r)

Submission status: Accepted

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

base = max(a)
tmp = 10**9
tmp_i = 0
for x in a:
    if x == base:
        pass
    elif abs(base - 2*x) < tmp:
        tmp = abs(base - 2*x)
        tmp_i = x

print(base, tmp_i)

Submission status: Accepted

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

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


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

# nCr : nが大きく、rがnの半分くらいの時が最大
maxA = max(A)
half = maxA/2

t = 10**10
for i in range(N):
    # 最大の要素ではない and 真ん中からの絶対値が小さい → 値を更新
    if A[i] != maxA and abs(A[i]-half) < abs(t-half):
        t = A[i]

print(maxA,t)

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int,input().split()))
ma = max(li)
li.remove(ma)
diff = []
for l in li:

    diff.append(abs(ma/2-l))
mi = min(diff)
ind = diff.index(mi)
print(ma,li[ind])

Submission status: Accepted

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

m = a[-1]
res = m
temp = 0
for i in range(n):
    if res > abs(m - 2*a[i]):
        res = abs(m - 2*a[i])
        temp = a[i]

print(m, temp)

Submission status: Accepted

Solution code:
#dpでできないかな？
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,pi,cos,radians,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
v=sorted(lis)
u=sorted(lis)[-1]
dis=[]
if u%2==0:
    k=u//2
    for i in range(n-1):
        dis.append(abs(v[i]-k))
    l=sorted(dis)[0]
    for i in range(n-1):
        if dis[i]==l:
            print(u,v[i])
            sys.exit()
else:
    k=(u-1)//2
    m=(u+1)//2
    for i in range(n-1):
        dis.append(abs(v[i]-k))
        dis.append(abs(v[i]-m))
    l=sorted(dis)[0]
    #print(l)
    for i in range(len(dis)):
        if l==dis[i]:
            print(u,v[i//2])
            sys.exit()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    A.sort()
    max_a = A[-1]
    A = A[:-1]
    A.sort(key=lambda a: abs(a - max_a / 2))
    print('{} {}'.format(max_a, A[0]))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

max_ele = 0
for i in range(len(a)):
    if a[i] > max_ele:
        max_ele = a[i]

mid = 0
mid_val = max_ele / 2

for j in range(len(a)):
    if abs(mid_val - a[j]) < abs(mid_val - mid):
        mid = a[j]

print(str(max_ele) + " " + str(mid))

Submission status: Accepted

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

max_val = max(A)
mid_val = max_val - max_val//2

# print("max_val: {}, mid_val: {}".format(max_val, mid_val))

m = 0
for a in A:
    # print(abs(a - mid_val))
    # print(abs(m - mid_val))
    if abs(a - mid_val) < abs(m - mid_val):
        m = a
    # print("m: {}".format(m))

print("{} {}".format(max_val, m))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = max(a)
a = sorted(a)
ans = 0
for i in a:
    if abs(m/2-i) < abs(m/2-ans):
        ans = i
print(m, ans)

Submission status: Accepted

Solution code:
import sys
import bisect

readline = sys.stdin.readline

def main():
    n = int(readline())
    a = list(map(int, readline().split()))
    a.sort()
    if len(a) == 2:
        a.sort(reverse=True)
        print(*a)
        return
    amax = a.pop()
    mid = amax//2
    mididx = bisect.bisect_left(a, mid)
    am1 = a[mididx]; am2 = a[mididx-1]
    if abs(am1-mid) <= abs(am2-mid):
        am = am1
    else:
        am = am2
    print(amax, am)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

a = sorted(a, reverse = True)
mid = a[0]//2
diff = abs(mid - a[0])

if n == 2:
    print(max(a[0],a[1]),min(a[0],a[1]))
else:
    for i in range(n):
        if abs(a[i] - mid) < diff:
            diff = abs(a[i] - mid)
            ans = i
    print(a[0], a[ans])

Submission status: Accepted

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

if N > 2:
    A.sort()
    num_total = A[-1]
    A.pop()
    def isOK(index, key, l):
        if l[index] >= key:
            return True
        else:
            return False
    
    def meguru_search(l,key): # key以上の値を持つ最小のインデックスを返す
        left = -1
        right = len(l)

        while (right - left) > 1: # 二分探索
            mid = left + (right - left)//2
            if isOK(mid,key,l):
                right = mid
            else:
                left = mid
        
        return right
    
    if num_total%2 == 0:
        Max = num_total//2 
    else:
        Max = num_total//2 + 1
    
    Maxind1 = meguru_search(A,Max) # Max以上の値を持つインデックス
    Maxind2 = Maxind1 - 1 # Max未満の最大の値を持つインデックス
    abs_1 = abs(Max - A[Maxind1])
    abs_2 = abs(Max - A[Maxind2])
    if abs_1 > abs_2: # Maxに近いほどnCrが大きい
        r = A[Maxind2]
    else:
        r = A[Maxind1]
    print(num_total,r)

else:
    print(max(A),min(A))

Submission status: Accepted

Solution code:
n = int(input())
a_ls = list(map(int, input().split()))
if n > 2:
    a_ls.sort()
    num_total = a_ls[-1]
    a_ls.pop()
    def isOK(index, key, l):
        if l[index] >= key:
            return True
        else:
            return False
    def meguru_search(l, key):
        '''
        key以上の値を持つ最小のインデックスを返す
        '''
        left = -1
        right = len(l)

        while (right - left) > 1:
            mid = left + (right - left) // 2
            # 直感的に記憶　
                # 「含まれている」んだったら「含むを許容（等号付き）する右側」はmidまで動かして問題ない
                    # 新しいrightの位置がkeyの位置だとしても、「含む」は許容されてる
                # 「含まれていない」んだったら「含まない(<)左の壁」をそこまで動かしてもkeyを通り過ぎることはない
            if isOK(mid, key, l):
                right = mid
            else:
                left = mid
        
        # whileを抜ける時、rightとleftは一個差で、かつkeyがrightの位置にある
        return right

    if num_total % 2 == 0:
        Max = num_total // 2
    else:
        Max = num_total // 2 + 1
    Maxind1 = meguru_search(a_ls, Max)
    Maxind2 = Maxind1 - 1
    abs_1 = abs(Max - a_ls[Maxind1])
    abs_2 = abs(Max - a_ls[Maxind2])
    if abs_1 > abs_2:
        r = a_ls[Maxind2]
    else:
        r = a_ls[Maxind1]
    print(num_total, r)
else:
    print(max(a_ls), min(a_ls))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
an = max(a)
mi = -1
ms = 10**10
an2 = an/2
for i in a:
    if ms > abs(i-an2) and not an == i:
        mi = i
        ms = abs(i-an2)

print(an,mi)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
c = a[0]
ch = -(-a[0]//2)
minD = 10**9
x = -1
for i in range(n):
    dif = abs(a[i]-ch)
    if minD>=dif:
        minD=dif
        x = a[i]
print(c,x)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n=int(input())
    A=list(map(int,input().split()))
    val=max(A)
    valind=A.index(val)
    minabs=10**18
    for i in range(n):
        if i==valind: continue
        if abs(A[i]-(val//2))<minabs:
            minabs=abs(A[i]-(val//2))
            val2=A[i]
    print(val,val2)    



    
resolve()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
 
m = max(a)
a = sorted(a)
 
ans = 0
 
for i in a:
    if abs(m/2-i) < abs(m/2-ans):
        ans = i
 
print(m, ans)

Submission status: Accepted

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

def isOK(index, key):
    return a[index] >= key

def bsearch(key):
    left = -1
    right = n-1

    while right-left > 1:
        mid = left+(right-left)//2
        if isOK(mid, key):
            right = mid
        else:
            left = mid

    if right == n-1:
        return -1
    else:
        return right

index = bsearch(r)

if index > 0 and 2*r < a[index-1]+a[index]:
    index -= 1

print(m, a[index])

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
A = getList()
A.sort()

max = max(A)
index = bisect_left(A, max / 2)
if abs((max / 2) - A[index]) < abs((max / 2) - A[index - 1]):
    ans = [max, A[index]]
else:
    ans = [max, A[index - 1]]
print(*ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = max(a)
r = -1
for i in a:
  if i != m and abs(m - 2 * i) < abs(m - 2 * r):
    r = i
print(m, r)

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    MAX = max(A)
    A = A[:-1]
    target = MAX / 2
    idx = bisect_left(A, target)

    if idx == 0:
        print(MAX, A[0])
    elif idx == N - 1:
        print(MAX, A[-1])
    else:
        if abs(target - A[idx]) < abs(target - A[idx - 1]):
            print(MAX, A[idx])
        else:
            print(MAX, A[idx - 1])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()
a = na()

max_a = max(a)
diff = inf
ans = 0
for i in range(n):
    if a[i] != max_a:
        d = abs(a[i] - max_a // 2)
        if diff > d:
            diff = d
            ans = a[i]

print(max_a, ans)

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce
import bisect
n = int(input())
A = sorted(list(map(int, input().split())))

big_num = A[-1]
near_mid_pointer = bisect.bisect_left(A, big_num / 2)
dif1 = 10**9 + 1
if near_mid_pointer != 0:
        dif1 = big_num / 2 - A[near_mid_pointer - 1]
dif2 = A[near_mid_pointer] - big_num / 2
if dif1 <= dif2:
    num1 = big_num
    num2 = A[near_mid_pointer - 1]

else:
    num1 = big_num
    num2 = A[near_mid_pointer]

print(num1, num2)

Submission status: Accepted

Solution code:
import bisect

n = int(input())
A = list(map(int, input().split()))
A.sort()
ama = A[-1]
print(ama, end=' ')
ama2 = (ama + 1)//2
w = bisect.bisect_left(A, ama2)

a = A[w-1]
b = A[w]
if abs(a-ama2) > abs(b-ama2):
    print(b)
else:
    print(a)

Submission status: Accepted

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

ai = max(a)
a.sort(key=lambda x: abs(ai//2 - x))
aj = a[0]
for i in a:
    if ai==i: continue
    else:
        aj = i
        break

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

Submission status: Accepted

Solution code:
def main():
  n = int(input())
  a = list(map(int, input().split()))
  a = sorted(a)
  a_i = a[-1]
  a_j = 0
  dist = a_i
  for i in range(len(a)-1):
    if abs(a_i/2-a[i]) < dist:
      a_j = a[i]
      dist = abs(a_i/2-a[i])
  print(a_i, a_j)

if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
import sys

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

if n==2:
    print(A[1],A[0])
    sys.exit()

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

Submission status: Accepted

Solution code:
import bisect
def main():
    N = int(input())
    A = sorted([int(_) for _ in input().split()])
    r = A[-1]//2
    B = A[:-1]
    x = bisect.bisect_left(B, r)
    if x == 0:
        return A[-1], B[x]
    elif x == N-1:
        return A[-1], B[x-1]
    else:
        if abs(B[x]-r) <= abs(B[x-1]-r): return A[-1], B[x]
        else: return A[-1], B[x-1]
if __name__ == '__main__':
    print(*main())

Submission status: Accepted

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


def solve(n: int, a: "List[int]"):
    b = sorted(a)
    n = b[-1]
    c = [(min(bb, n-bb), bb) for bb in b[:-1]]
    return n, max(c)[1]


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
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]"
    print(*solve(n, a))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

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

ai = max(a)
aj = min(a)

for i in a:
    if min(aj, ai -aj) < min(i, ai - i):
        aj = i
    
print(ai, aj)

Submission status: Accepted

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

m = max(a)
a = sorted(a)

ans = 0

for i in a:
    if abs(m/2-i) < abs(m/2-ans):
        ans = i

print(m, ans)

Submission status: Accepted

Solution code:
def pow(x, n , mod):
    res = 1
    while n > 0:
        if  bin(n & 1) == bin(1) :
            res = res * x % mod
        x = x*x % mod
        n = n >>1
    return res   

def combination(n,a):
    x = 1
    for i in range(a):
        x = x * (n-i) % mod
    y = 1
    for i in range(a):
        y = y * (a-i) % mod
    y = pow(y, mod-2, mod)
    return (x*y % mod)

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

m = max(a)
a = sorted(a)

ans = 0

for i in a:
    if abs(m/2-i) < abs(m/2-ans):
        ans = i

print(m, ans)

Submission status: Accepted

Solution code:
dp_t = dict()
dp_p = dict()


def main():
    n = int(input())
    a = [int(s) for s in input().split(" ")]
    a.sort(reverse=True)
    t = a[0] // 2
    p = a[-1]
    if n == 2:
        print("%d %d" % (a[0], a[1]))
        return
    i = 1
    while a[i] > t:
        i += 1
        if i >= n:
            i -= 1
            break
    if abs(a[i - 1] - t) > abs(a[i] - t):
        p = a[i]
    else:
        p = a[i - 1]
    print("%d %d" % (a[0], p))


def main1():
    n = int(input())
    a = [int(s) for s in input().split(" ")]
    a.sort(reverse=True)
    max_comb = (0, 0)
    max_num = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            c = comb(a[i], a[j])
            if max_num < c:
                max_num = c
                max_comb = (a[i], a[j])
    print("%d %d" % max_comb)


def comb(n, r):
    t = 1
    if n in dp_t:
        t = dp_t[n]
    else:
        t = compute_kai(n)
    p = 1
    if (n, r) in dp_p:
        p = dp_p[(n, r)]
    else:
        pr = 1
        if r in dp_t:
            pr = dp_t[r]
        else:
            pr = compute_kai(r)
        if n - r in dp_t:
            p = dp_t[n - r]
        else:
            p = compute_kai(n -r)
        p *= pr
        dp_p[(n, r)] = p
    return t // p


def compute_kai(n):
    if n in dp_t:
        return dp_t[n]
    else:
        t = 1
        for i in range(n):
            t *= (n - i)
        dp_t[n] = t
        return t


if __name__ == '__main__':
    main()

Submission status: Accepted

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