#C8785. Find Closest Pair Sum to Zero
Find Closest Pair Sum to Zero
Find Closest Pair Sum to Zero
You are given an array of n integers. Your task is to find two distinct numbers from the array whose sum is closest to zero. In other words, if the two numbers are \(a\) and \(b\), you want to minimize \(|a+b|\). If there are multiple pairs achieving the same minimum absolute sum, any one of them can be printed.
Note: The input is given as follows: the first line contains an integer \(n\) \( (2 \leq n \leq 10^5)\), and the second line contains \(n\) integers. You must output the two numbers separated by a space in one line. The solution should use an efficient strategy such as sorting with two pointers.
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains one integer \(n\), the number of elements in the array.
- The second line contains \(n\) space-separated integers which represent the elements of the array.
outputFormat
The output should be printed to stdout as two integers separated by a space. These integers represent a pair from the array whose sum is closest to zero. In case of multiple valid answers, any one pair is acceptable.
## sample5
-1 2 4 -3 1
-1 1