The problem can be reworded as: Choose , such that
is minimum, and
An easy way to solve this is by using Lagrange multipliers:
If we write this as:
We can see that as increases(decreases), increases(decreases), so we can do a binary search for the value of that satisfies