#C3867. Minimum Difference Pair
Minimum Difference Pair
Minimum Difference Pair
You are given one or more arrays along with a target value for each test case. For each test case, you need to find two distinct elements in the array whose absolute difference is as close as possible to the given target. More formally, if the two elements are \(a\) and \(b\), then you need to minimize the quantity \(|\,|a-b| - target|\). After finding such a pair, output the value of \(|a-b|\) for that test case.
Note: If there are multiple pairs with the same closeness to the target, you may output the absolute difference of any one of those pairs.
The mathematical formulation for each test case is:
[ \min_{i<j} ; \Big|,|a_i - a_j| - T\Big|, ]
where \(T\) is the target value, and the output is the computed absolute difference \(|a_i-a_j|\) corresponding to that minimum value.
inputFormat
The input begins with an integer \(T\) representing the number of test cases.
For each test case:
- The first line contains an integer \(n\) indicating the number of elements in the array.
- The second line contains \(n\) space-separated integers representing the array.
- The third line contains an integer representing the target value for that test case.
All input should be read from standard input.
outputFormat
For each test case, output a single line containing one integer: the absolute difference \(|a-b|\) of the two elements whose difference is closest to the target value.
All output should be written to standard output.
## sample2
5
1 3 15 11 2
5
4
19 10 7 12
3
4
3
</p>