
Perfect stairs problem
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.

You should have shown some code... Useless to help elsewise... Kind of! :P
But, I made one little thing up for you, hope it helps you in the right direction! :)
Code:
#include <iostream>
#include <iomanip>
#include <stdio.h>
using namespace std;
//Global
int stones[10]; //10 steps, goes from 0 to 9, 10 doesnt count :P
void sortout()
{
//Order so the "Left pile stone", the index 0 (stones[0]) is the minimum value
int tempvariable;
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
if(stones[i] < stones[j]) //Stones [j] is larger than [i], switch those two
{
tempvariable = stones[i];
stones[i] = stones[j];
stones[j] = tempvariable;
}
}
}
for(int i = 0; i < 10; i++)
{
cout << "After rearrangement, lowest first: " << stones[i] << endl;
}
}
int main()
{
int ii;
for(int i = 9; i > 1; i)
{
//Creating each 10 steps, initialized to value 9,8,7,6,5,4...
stones[i] = i;
cout << "Step " << stones[i] << endl;
}
//call sorting out, so left is stones[0], lowest pile of stones.
sortout();
return 0;
}
After you run this little program, then you can draw "stones[0]" to the left, which will have the lowest amount of piles.