Nested ternary search can be applied when we have an optimization problem with two unknowns. This task is just about that.
Obviously, the gate will be in the shape of a quadrilateral, with a right angle at the base, then we just have to choose 2 corners (α
and β
) so that the area gate was maximum. To do this, we create a ternary search that will give us 2 corners (α1
and α2
), and for each of these α
we will run another ternary search, which will select such β
for which the area will be maximum.
Read more here