I have two arrays that both contain $n$ elements (positive, non zero, not negative)
$\{x_1\dots x_n\}$
$\{y_1\dots y_n\}$
I want to pair them up optimally, one from each array, so that the pairs come out as even as possible, when paired up optimally. I want the difference between the highest sum of pair values and the lowest such sum to be as small as possible.
I know there are brute force ways but they take $O(n^2)$ time, and I want the time complexity to be low, say $O(n^{1.5})$ or lower.
My approach is to sort one of the arrays in ascending order, and one in descending order and pair them up.
How would I go about making sure they are actually paired optimally so that difference between the smallest sum and the highest sum among pairs is as small as possible?