Sorting Jojo was given a Math assignment by his teacher. Jojo's task is to sort a number of given then find the closest pair of numbers that has the maximum difference after sorted. Jojo was asked to write down a list of the pairs of numbers. Input Format The first line of input is an integer N i.e. the number of numbers The second line is a series of numbers Ai as many as N Output Format Pairs of numbers separated by spaces Constraints 2 ≤ N ≤ 105 -107 ≤ Ai ≤ 107 Sample Input 5 2 -8 3 1 -10 Sample Output -8 1 Sample Input 10 45 9 3 -6 100 68 -57 23 -11 -25 Sample Output -57 -25 68 100 In the sample above if the input is sorted then: -10 -8 1 2 3 so that the difference between each number in sequence is 2, 9, 1, 1 -57 -25 -11 -6 3 9 23 45 68 100 so the difference is 32, 14, 5, 9, 6, 14, 22, 23, 32 Notes Even though it wasn't stated in the problem, by now you should know that the advantages spaces or lines are considered WRONG ANSWER.
Sorting
Jojo was given a Math assignment by his teacher. Jojo's task is to sort a number of given then find the closest pair of numbers that has the maximum difference after sorted. Jojo was asked to write down a list of the pairs of numbers.
Input Format
The first line of input is an integer N i.e. the number of numbers
The second line is a series of numbers Ai as many as N
Output Format
Pairs of numbers separated by spaces
Constraints
2 ≤ N ≤ 105
-107 ≤ Ai ≤ 107
Sample Input
5
2 -8 3 1 -10
Sample Output
-8 1
Sample Input
10
45 9 3 -6 100 68 -57 23 -11 -25
Sample Output
-57 -25 68 100
In the sample above if the input is sorted then:
-10 -8 1 2 3 so that the difference between each number in sequence is 2, 9, 1, 1
-57 -25 -11 -6 3 9 23 45 68 100 so the difference is 32, 14, 5, 9, 6, 14, 22, 23, 32
Notes
Even though it wasn't stated in the problem, by now you should know that the advantages spaces or lines are considered WRONG ANSWER.
Step by step
Solved in 2 steps