On the test that I'm studying for I have a problem to solve but I don't know how to solve that. The problem is the following:

I have various piles of square stones and I need to organize that to make the most perfect possible stairs. There must be 1 stone of difference between each pile. The smallest pile must be always on the left. I'll give a picture to help (the pile of stone is on the left and the organizada pile is on the right):

http://img180.imageshack.us/img180/9316/testth.png

Does anyone know a known algorithm to do this?

Thank you,

Rafael Andreatta

EDIT: Ops I forgot to mention what's my input format.

I have the number of piles of stones and the number of stones in each pile.