I have a task:

There is a screen size MxN and it is covered with cuboids with different height(there are MxN cuboids) . The water is poured out on it. I have to calculate capacity of water which remain in cuboids. I have to find few algoriths and compare time of calculation. I'll be grateful for quick help!!!