Problem 373
Minimum Absolute Difference Pairs
Easy · 10 pts · Array, Sorting
Problem
The array contains distinct integers. Find the smallest absolute difference between any two of them, then print every pair of values (a, b) with a < b whose difference is exactly that minimum. Print the pairs in ascending order of a. After sorting, the minimum difference is always between neighbours, so one pass over the sorted array finds every pair.
Input
First line: N. Second line: N distinct integers.
Output
Print each pair on its own line as: a b.
Constraints
2 <= N <= 100000; -1000000 <= A[i] <= 1000000; values are distinct
Example input
4 4 2 1 3
Example output
1 2 2 3 3 4
Explanation
Sorted, the array 4 2 1 3 becomes 1 2 3 4. Every neighbouring difference is 1, which is the minimum, so the pairs are 1 2, 2 3 and 3 4.