My problem is a bit similar to this topic :
Although in my case I have a container of some size, and some predefined elements with know vertical positions. The elements are to be allocated inside the container without overlapping, and taking full available width. If two or more would overlap, they should have the same width.
Anyone knows any algorithms that may be helpful here ?
Well one way would be to model this problem as a convex optimization problem and then use a solver to solve it (tons of solvers are available online). You can find more info about this approach in floor planning chapter (page 438) of Boyds convex optimization book. They have a matlab implementation of it in the examples folder of cvx software. I hope I haven't made it more complicated, it would be interesting to see other solutions.