#C13654. Find the Closest Pair
Find the Closest Pair
Find the Closest Pair
You are given a list of integers and a target integer, \(T\). Your task is to find two numbers in the list such that the absolute difference between their sum and the target \(T\) is minimized. Formally, if the two numbers are \(a\) and \(b\), you need to minimize \(|a+b - T|\).
If the list contains fewer than two elements, output None None
.
If there are multiple pairs achieving the same minimum difference, any one of them is accepted.
inputFormat
The input is given via stdin and consists of two lines. The first line contains two integers \(n\) and \(T\), where \(n\) is the number of elements in the list and \(T\) is the target integer.
The second line contains \(n\) integers separated by spaces.
outputFormat
Output the two integers forming the pair separated by a space to stdout. If no valid pair exists (i.e. if \(n < 2\)), output None None
.
6 54
10 22 28 29 30 40
22 30