I'm trying to stack $n$ rectangles with size $a \times b$ to minimize the distance from the origin to the furthest point ($L$).
I attach a couple of images to clarify.
Thanks for you help!
Jorge
I'm trying to stack $n$ rectangles with size $a \times b$ to minimize the distance from the origin to the furthest point ($L$).
I attach a couple of images to clarify.
Thanks for you help!
Jorge
Copyright © 2021 JogjaFile Inc.


A greedy algorithm will work.
It suffices to show that if we have two boxes stack on top of each other, the higher one will have a greater L. Hence we just maintain a priority queue of all the possible locations to put a box, then choose the one with the smallest L, place it and insert the new possible locations into the priority queue.