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 heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


# ワーシャルフロイド (任意の2頂点の対に対して最短経路を求める)
# 計算量n^3 (nは頂点の数)
def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
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

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定



# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
n = int(input())
a = sorted(list(map(int, input().split())))
ai = max(a)
if ai % 2 == 0:
    d = INF
    aj = 0
    for i in a[:-1]:
        if abs(i - ai // 2) < d:
            aj = i
            d = abs(i - ai // 2)
    print(ai, aj)
else:
    d = INF
    aj = 0
    for i in a[:-1]:
        if min(abs(i - ai // 2), abs(i - ai // 2 - 1)) < d:
            aj = i
            d = min(abs(i - ai // 2), abs(i - ai // 2 - 1))
    print(ai, aj)

Submission status: Accepted

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

a = max(As)

# 一番a/2に近い数を選ぶ
b = None
dist = float('inf')
for i in range(n):
    if As[i] != a and abs(As[i] - a/2) < dist:
        dist = abs(As[i] - a/2)
        b = As[i]

print(a, b)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
ai = a[-1]
aj = a[0]
center = ai // 2
diff = 10**10

for i in range(n-1):
    if abs(center - a[i]) <= diff and aj < a[i]:
        diff = abs(center - a[i])
        aj = a[i]

print(str(ai) + " " + str(aj))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
ai = a[-1]
aj = a[0]
center = ai // 2
diff = 10**10
# print("-----------")
# print(center)

for i in range(n-1):
    if abs(center - a[i]) <= diff and aj < a[i]:
        diff = abs(center - a[i])
        aj = a[i]
        # print(diff)
        # print(aj)
        # print("----")


print(str(ai) + " " + str(aj))

Submission status: Accepted

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

max_a = max(a)
a.remove(max_a)
da = [abs(ai - max_a / 2) for ai in a]
med_i = da.index(min(da))

print("%d %d" % (max_a, a[med_i]))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
max_a = max(a)
a.remove(max_a)
da = [abs(ai - max_a/2) for ai in a]
med_i = da.index(min(da))
print(max_a, a[med_i])

Submission status: Accepted

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

a_l.sort(reverse=True)
ans_n = a_l[0]
a_l2 = []
for i, val in enumerate(a_l):
    a_l2.append((abs(val-float(ans_n)/2),i))
a_l2.sort()

if a_l2[0][1] == 0:
    ans_r_index = a_l2[1][1]
else:
    ans_r_index = a_l2[0][1]
ans_r = a_l[ans_r_index]
print(ans_n, ans_r)

Submission status: Accepted

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

n=alst.pop()
center=n/2
cost=10**10

for a in alst:
    if abs(a-center)<cost:
        cost=abs(a-center)
        r=a

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

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A_sorted = sorted(A)
    A_max = A_sorted[-1]
    A = A_sorted[:-1]
    tansaku = (A_max + 1) // 2
    ok = 0
    ng = len(A) - 1
    if A[ok] > tansaku:
        print(A_max, A[ok])
        exit()
    if A[ng] <= tansaku:
        print(A_max, A[ng])
        exit()
    while ok + 1 < ng:
        center = (ok + ng) // 2
        if A[center] <= tansaku:
            ok = center
        else:
            ng = center
    if tansaku - A[ok] <= A[ng] - tansaku:
        print(A_max, A[ok])
    else:
        print(A_max, A[ng])

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    N = II()
    A = LMIIS()
    A.sort()
    n = A[-1]
    r = A[0]
    for i in range(1,N-1):
        if abs(A[i]-n/2) < abs(r-n/2):
            r = A[i]

    print(n,r)


    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

M = max(a)

a = sorted(a)
a = [a[i] for i in range(n-1)]

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

print('{} {}'.format(M,b))

Submission status: Accepted

Solution code:
N = int(input())
arr = list(map(int, input().split()))
target_n = max(arr)
target_m = 0
tmp = float('inf')
for i in range(N):
    if abs((target_n/2)-arr[i]) <= tmp and target_n != arr[i]:
        target_m = arr[i]
        tmp = abs((target_n/2)-arr[i])
print(target_n,target_m)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
kar = max(a)
a.remove(kar)
mid = kar//2
tyu = 10**10
if kar % 2 == 0:
    for i in range(n-1):
        if tyu > abs(mid-a[i]):
            tyu = abs(mid-a[i])
            ans = a[i]
elif kar % 2 == 1:
    for i in range(n-1):
        if tyu > min(abs(mid-a[i]),abs(mid+1-a[i])):
            tyu = min(abs(mid-a[i]),abs(mid+1-a[i]))
            ans = a[i]
print(str(kar) + " " + str(ans))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, *a = map(int, read().split())
a.sort()
tmp = float('inf')
index = 0
for i, aa in enumerate(a):
    v = abs(a[-1] / 2 - aa)
    if v < tmp:
        tmp = v
        index = i
print(a[-1], a[index])

Submission status: Accepted

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

ai = numbers[-1]
r = ai / 2

for i in range(n - 1):
    if numbers[i] == r:
        ans = [ai, int(r)]
        break
    if numbers[i] > r:
        if numbers[i] - r < r - numbers[i - 1]:
            ans = [ai, numbers[i]]
        break
    ans = [ai, numbers[i]]

print(*ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
import math
def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    l.sort(reverse=True)
    a=l[0]
    l.pop(0)
    bnum=0
    bmax=0
    for i in l:
        bb=min(i,a-i)
        if bmax<bb:
            bnum=i
            bmax=bb
    print(a,bnum)
resolve()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
import math
def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    l.sort(reverse=True)
    ans=0
    jissitu=0
    naka=l[0]//2
    for i in range(1,n):
        if l[i]>naka and l[0]-i>jissitu:
            ans=l[i]
            jissitu=l[0]-l[i]
        elif l[i]<=naka and l[i]>jissitu:
            ans=l[i]
            jissitu=l[i]
    print(l[0],ans)
resolve()

Submission status: Accepted

Solution code:
from bisect import bisect_left


def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    a.sort()
    if n > 2:
        index = bisect_left(a, a[-1] // 2)
        if index == n - 1:
            index -= 1
        elif index > 0 and a[-1] - a[index] < a[index - 1]:
            index -= 1
        print(a[-1], a[index])
    else:
        print(a[1], a[0])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
n = int(input())
a = sorted(list(map(int,input().split())))
b = (a[-1]+1)//2
d = float("inf")
for i in a:
    if abs(b-i) < d:
        d = abs(b-i)
        ans = i
print(a[-1],ans)

Submission status: Accepted

Solution code:
import sys
def main():
    input = sys.stdin.readline
    n=int(input())
    *A,=map(int, input().split())
    #mCr
    m,r=max(A),0
    maxd=0
    for a in A:
        if a>=m: continue
        d = min(a,m-a)
        if maxd<d:
            maxd=d
            r=a
    print(m,r)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

half=max(A)/2
MAX=max(A)
now=MAX
ans=0
for a in A:
    if now>abs(a-half):
        now=abs(a-half)
        ans=a

print(MAX,ans)

Submission status: Accepted

Solution code:
def main():
    _ = int(input())
    A = [int(i) for i in input().split()]
    A.sort()
    ma = A[-1]

    mi = 10**9+1
    idx = -1
    for i, v in enumerate(A):
        if ma % 2:
            if abs(ma//2 - v) < mi:
                mi = abs(ma//2 - v)
                idx = i
            if abs(0--ma//2 - v) < mi:
                mi = abs(0--ma//2 - v)
                idx = i
        else:
            if abs(ma//2 - v) < mi:
                mi = abs(ma//2 - v)
                idx = i
    print(ma, A[idx])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = A[-1]
target = math.ceil(A[-1] / 2)
dis = float('inf')
for a in A:
    tmp_dis = abs(target - a)
    if tmp_dis < dis:
        dis = tmp_dis
        tmp_ans = a
print(ans, tmp_ans)

Submission status: Accepted

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

from bisect import bisect
i = bisect(A, A[-1]//2)
a = min(A[i], A[-1]-A[i])
b = min(A[i-1], A[-1]-A[i-1])
if a > b:
    print(A[-1], A[i])
else:
    print(A[-1], A[i-1])

Submission status: Accepted

Solution code:
from bisect import bisect_left
n = int(input())
A = sorted(list(map(int,input().split())))
ind = bisect_left(A,A[-1]//2)
if A[ind]==A[-1]//2:
    print(A[-1],A[ind])
else:
    if ind>0 and A[ind-1]>=A[-1]-A[ind]:
        print(A[-1],A[ind-1])
    else:
        print(A[-1],A[ind])

Submission status: Accepted

Solution code:
import math
import bisect


n = int(input())

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

ncr = 0
ans = [0, 0]

id = bisect.bisect_left(a[:n-1], a[n-1]//2)
if abs(a[-1]/2 - a[id]) < abs(a[-1]/2 - a[id-1]):
    ans = id
else:
    ans = id-1

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
N = float("INF")
ans = 0
for i in range(1,n):
    if abs(a[i]-(a[0]-a[i])) < N:
        N = abs(a[i]-(a[0]-a[i]))
        ans = a[i]
print(a[0], ans)

Submission status: Accepted

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

from bisect import bisect
i = bisect(A, A[-1]//2)
a = min(A[i], A[-1]-A[i])
b = min(A[i-1], A[-1]-A[i-1])
if a > b:
    print(A[-1], A[i])
else:
    print(A[-1], A[i-1])

Submission status: Accepted

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

if sai%2==0:
  b=sai//2
  hantei=10**9+1
  suuji=0
  for i in a:
    if abs(b-i)<hantei and i!=sai:
      hantei=abs(b-i)
      suuji=i
  print(sai,suuji)
else:
  b1=sai//2
  b2=sai//2+1
  hantei=10**9
  suuji=0
  for i in a:
    if min(abs(b1-i),abs(b2-i))<hantei:
      hantei=min(abs(b1-i),abs(b2-i))
      suuji=i
  print(sai,suuji)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
max=0
for i in range(n):
  if a[i]>max:
    max=a[i]
min=1000000000000
minans=0
for i in range(n):
  if a[i]==max:
    continue
  if abs(a[i]-max/2)<min:
    min=abs(a[i]-max/2)
    minans=a[i]
print(max)
print(minans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
l = []
for i in range(n - 1):
    l.append(abs(a[-1] / 2 - a[i]))
print(a[-1], a[l.index(min(l))])

Submission status: Accepted

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

N = A.pop()
K = -1
d = -1
for a in A:
    r = min(a, N - a)
    if r > d:
        d = r
        K = a

print(N, K)

Submission status: Accepted

Solution code:

import bisect
def near_abs_id(a,target,fast=True): # a:listの中で絶対値がもっともtargetに近い要素のindex
    # 複数存在する場合は一番indexが小さいもの
    if fast: # O(logn)　### 昇順にソート済みで，全て正の数であることが必要
        idx = bisect.bisect_left(a,target)
        if idx==0: return idx
        elif idx==len(a): return len(a)-1
        else:
            if idx==len(a)-1:
                if abs(a[idx-1]-target)<=abs(a[idx]-target):
                    return idx-1
                else:
                    return idx
            else:
                now = abs(a[idx+1]-target)
                ans = idx+1
                for i in (0,-1):
                    if abs(a[idx+i]-target)<=now:
                        ans -= 1
                        now = abs(a[idx+i]-target)
                return ans
    else: # O(n)
        idx = 0
        m = float('inf')
        for i in range(len(a)):
            if abs(a[i]-target) < m:
                m = abs(a[i]-target)
                idx= i
        return idx

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

a.sort()
m = a[-1]
j=near_abs_id(a,m/2)
if j==n-1:
    j-=1
print(m,a[j])

Submission status: Accepted

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

a.sort()
m = a[-1]
def near_abs_id(l,n): # リストlの中で絶対値がもっともnに近い要素のindex
    idx = 0
    m = 10**12
    for i in range(len(l)):
        if abs(l[i]-n) < m:
            m = abs(l[i]-n)
            idx= i
    return idx
j = near_abs_id(a,m/2)
if j==n-1:
    j-=1
print(m,a[j])

Submission status: Accepted

Solution code:

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


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


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


show_flg = False
# show_flg = True


def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


def main():
    N = MI()
    a = LI()
    a = sorted(a, reverse=True)
    mx = a[0]

    if mx % 2 == 0:
        target = mx // 2
        mn = 10**9
        ans = -1
        for i in range(1, len(a)):
            if mn > abs(target - a[i]):
                ans = a[i]
                mn = abs(target - a[i])
        print(a[0], ans)
    else:
        target1 = mx // 2
        target2 = mx // 2 + 1
        mn = 10**9
        ans = -1
        for i in range(1, len(a)):
            if mn > abs(target1 - a[i]):
                ans = a[i]
                mn = abs(target1 - a[i])
            if mn > abs(target2 - a[i]):
                ans = a[i]
                mn = abs(target2 - a[i])
        print(a[0], ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ai = a[0] / 2
aj = 0
comb = 10 ** 10
for i in range(n):
    temp = abs(a[i] - ai)
    if comb >= temp:
        comb = temp
        aj = a[i]
print(a[0], aj)

Submission status: Accepted

Solution code:
from bisect import bisect_left
N = int(input())
A = list(map(int,input().split()))
A.sort()
n = A.pop()
index = bisect_left(A, n//2)
if index == 0:
    r = A[0]
elif index == N-1:
    r = A[N-2]
else:
    if abs(n//2-A[index]) <= abs(n//2-A[index-1]):
        r = A[index]
    else:
        r = A[index - 1]
print(*[n,r])

Submission status: Accepted

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

l = A[-1]
m = A[-1]//2
r = 0
tmp = 0
for i in range(N):
    d = min(abs(l-A[i]), abs(0-A[i]))
    if tmp < d:
        r = A[i]
        tmp = d

print(l, r)

Submission status: Accepted

Solution code:
N, *A = map(int, open(0).read().split())

A.sort()
x = [abs(A[-1] - 2 * A[i]) for i in range(N - 1)]
y = sorted((v, i) for i, v in enumerate(x))
print(A[-1], A[y[0][1]])

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=max(a)
ansmax=-1
ans=-1
for i in range(n):
  if min(b-a[i],a[i]) > ansmax and b!=a[i]:
    ansmax=min(b-a[i],a[i]) 
    ans=a[i]
print(str(b)+' '+str(ans))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=[]
M=a[n-1]
for i in range(n-1):
    b.append(M-a[i])
c=a+b
c.sort()

import bisect
index=bisect.bisect_right(c,M//2)-1

if c[index] in a:
    print(M,c[index])
else:
    print(M,M-c[index])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,(input().split())))
M = max(a)
a.remove(M)
nim = 10**9
for i in range(len(a)):
    d = abs(M - a[i]*2)
    if d < nim:
        nim = d
        nimi = i
print(M,a[nimi])

Submission status: Accepted

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


maxA = max(A)
tmp = min(A)

d = maxA/2

for a in A:
    if abs(d-a) < abs(d-tmp):
        tmp = a

print(maxA, tmp)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc094/tasks/arc095_b
n = int(input())
nums = [int(i) for i in input().split()]

# すべてを計算する時間はなさそう
# 最大のモノを選らんで、それと絶対値差が大きいモノを選ぶ。いや、ここは全部やればいいのかな。
# numsの値がめちゃくちゃでかいので、全部はできない。

MAX = max(nums)
t = 0
ans = 0
for num in nums:
    if num == MAX:
        continue
    d = min(MAX - num, num)
    if t < d:
        t = d
        ans = num
print(MAX, ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
ma = lambda : map(int,input().split())
ni = lambda : int(input())

n = ni()
A = list(ma())
A.sort()
ma = A[-1]
mi = -1

for a in A:
    if abs(a - ma/2) <abs(mi - ma/2):mi =a

print(ma,mi)

Submission status: Accepted

Solution code:
# python3.4.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')

n = iin()
a = sorted(iln(), reverse=True)

MAX = a[0]
diff = MAX
r = 0
for i in range(1,n):
    tmp_diff = abs(2*a[i]-MAX)
    if tmp_diff < diff:
        diff = tmp_diff
        r = a[i]
print(MAX, r)

Submission status: Accepted

Solution code:
n = int(input())
A = sorted(map(int, input().split()))
n = A[-1]
mi = 10 ** 9
for a in A[:-1]:
    if mi > abs(n/2 - a):
        mi = abs(n/2 - a)
        r = a
print(n, r)

Submission status: Accepted

Solution code:
from bisect import bisect_left,bisect_right

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

maxi=a[-1]
tmp=maxi/2
idx=bisect_left(a,tmp)

if a[idx]-tmp > tmp-a[idx-1] :
  idx += -1

if idx==n-1:
  idx += -1
  
print(maxi,a[idx])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=sorted(limii())


a=arr[-1]

def take_closest(myList, myNumber):
    """
    Assumes myList is sorted. Returns closest value to myNumber.

    If two numbers are equally close, return the smallest number.
    """
    pos = bisect_left(myList, myNumber)
    if pos == 0:
        return myList[0]
    if pos == len(myList):
        return myList[-1]
    before = myList[pos - 1]
    after = myList[pos]
    if after - myNumber < myNumber - before:
       return after
    else:
       return before

print(a,take_closest(arr,a/2))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
ai = max(a)
aj = -1
dj = ai
for ak in a:
    if ak == ai:
        continue
    dk = abs(ai // 2 - ak)
    if dk < dj:
        aj = ak
        dj = dk
print(ai, aj)

Submission status: Accepted

Solution code:
n = int(input())
ns = list(map(int, input().split()))
a = max(ns)
ns.remove(a)
b = a / 2
c = min(abs(j - b) for j in ns)
d = [i for i in ns if abs(i - b) == c][0]
print(a, d)

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc094/tasks/arc095_b
# 15:10-15:18


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A = sorted(A)

    ai = A[-1]
    aj = A[0]
    border = ai / 2
    for j in range(N):
        if abs(border-A[j]) < abs(border-aj):
            aj = A[j]
    
    return ai, aj


for x in main():
    print(x, end=" ")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    n=int(input())
    a=list(map(int,input().split()))
    a.sort()
    i=bisect_left(a,a[-1]//2)
    if i==n-1:
        print(a[-1],a[i-1])
    else:
        if min(a[i],a[-1]-a[i])>min(a[i-1],a[-1]-a[i]):
            print(a[-1],a[i])
        else:
            print(a[-1],a[i-1])
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import bisect

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = sorted(list(map(int, input().split())))
    if n == 2:
        print(*A[::-1])
        exit()

    idx = bisect.bisect_left(A, A[-1] // 2)
    if abs(A[-1] - A[idx] - A[-1] // 2) > abs(A[-1] - A[idx - 1] - A[-1] // 2):
        idx -= 1

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans1 = max(A)
    ans2 = 0
    diff = ans1
    for a in A:
        if a == ans1:
            continue
        d1 = abs(ans1/2 - a)
        if d1 < diff:
            diff = d1
            ans2 = a
        d2 = abs(a - ans1/2)
        if d2 < diff:
            diff = d2
            ans2 = a

    print(ans1, ans2)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
if N == 2:
    print(max(a), min(a))
    quit()
a.sort()
from bisect import bisect_left
#for i in range(N):
cur = a[N - 1] // 2
s = bisect_left(a, cur)
min_ = float('Inf')
for i in range(-1, 2):
    #print(i)
    if min_ > abs(a[N - 1] - 2 * a[s + i]):
        min_ = abs(a[N - 1] - 2 * a[s + i])
        arg = i
print(a[N - 1], a[s + arg])

Submission status: Accepted

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n = ni()
    a = nl()

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

    right = bisect_left(a, max(a)/2)
    left = right - 1

    if abs(max(a)/2 - a[left]) <= abs(max(a)/2 - a[right]):
        ans.append(a[left])
    else:
        ans.append(a[right])

    if ans[0] == ans[1]:
        ans[1] = 0

    print(*ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a1 = max(a)
half = a1/2
a2 = 0
for t in a:
  if abs(a2-half) > abs(t-half):
    a2 = t
print('{} {}'.format(a1, a2))