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

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Memory Limit Exceeded)


import java.util.Arrays;
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);
    static int n;
    static int[] a;

    public static void main(String[] args) {
        n = sc.nextInt();
        a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        //a[a.length-1]/2に一番近いもの
        if (n == 2) {
            index = 0;
        } else {
            search(a[a.length - 1] / 2, 0, a.length - 2);
        }

        System.out.println(a[a.length - 1] + " " + a[index]);
    }

    static int diff = Integer.MAX_VALUE;
    static int num = Integer.MIN_VALUE;
    static int index = Integer.MIN_VALUE;

    private static void search(int target, int min, int max) {
        if (max - min <= 1) {
            if (Math.abs(target - a[max]) <= diff && num < a[max]) {
                diff = Math.abs(target - a[max]);
                num = Math.max(num, a[max]);
                index = max;
            }
            if (Math.abs(target - a[min]) <= diff && num < a[min]) {
                diff = Math.abs(target - a[min]);
                num = Math.max(num, a[min]);
                index = min;
            }
            return;
        }
        int mid = (max - min) / 2;
        if (Math.abs(a[mid] - target) > diff) {
            return;
        }
        if (Math.abs(a[mid] - target) <= Math.abs(a[mid + 1] - target)) {
            search(target, min, mid);
        }
        if (Math.abs(a[mid] - target) >= Math.abs(a[mid + 1] - target)) {
            search(target, mid + 1, max);
        }
    }
}