Calculate TI HI given carton dimensions and pallet area

Im trying to figure out how many cartons can fit on a pallet. Normally quite simple if you have the physical cartons but I do not, they are still on a container ship.

The cartons are various sizes but lucky for me there is only 1 carton size/type per pallet.

One thing to note is that depending on the size of the carton, sometimes there is "air space"...ie the cartons do not cover the pallet evenly. eg Long cartons will stack so there is a hole in the middle like a donut. But small square cartons will stack nicely like a rubic cube. So the formula needs to be able to take that into account.

Pallet area is roughly 120cm * 120cm The height that cartons are allowed to be stacked safely is 160cm

So if i know the dimensions of the cartons and the pallet dimensions, what is the formula i need to work out the TI HI.
TI = cartons per layer on a pallet
HI = number of layers

Apologies if I did not tag this question properly

-

If you stack the cartons with the same dimension vertical, then $HI=\lfloor \frac {160}h \rfloor$, where $h$ is the height of the carton in cm. Similarly, if you stack the cartons in the same orientation, then the number in one dimension is $L=\lfloor \frac {120}l \rfloor$ and in the other $W=\lfloor \frac {120}w \rfloor$ where $l$ and $w$ are the length and width in cm. There may be better arrangements depending on the shape of your cartons. You probably do want the same dimension vertical, but the horizontal arrangement can have improvements. Often they are obvious by cutting out rectangles of paper and playing a bit.