Imagine that we have successfully processed first

Now I will describe how to calculate Δ

I.

II.

Then there are three slightly more complicated cases.

1.

touching it's sides. From the similarity of some triangles we get that .

2.

touching it's sides. From the similarity of some triangles we get that .

3.

Note that, for example, cases 1 and 2 do not exclude each other, so the final value of Δ

Note that if the calculated value of Δ

*i*- 1 bowls, i.e. we know height of the bottom*y*_{j}for every bowl*j*(1 ≤*j*<*i*). Now we are going to place*i*-th bowl. For each*j*-th already placed bowl, we will calculate the relative height of the bottom of*i*-th bowl above the bottom of*j*-th bowl, assuming that there are no other bowls. Lets denote this value by Δ_{i, j}. It is obvious that height of the new bowl is equal to the maximal of the following values:*y*_{i}=*max*(*y*_{j}+ Δ_{i, j}).Now I will describe how to calculate Δ

_{i, j}. Firstly, consider two trivial cases:I.

*r*_{i}≥*R*_{j}: bottom of*i*-th bowl rests on the top of*j*-th. Then Δ_{i, j}=*h*_{j}.II.

*R*_{i}≤*r*_{j}: bottom of*i*-th bowl reaches the bottom of*j*-th. Then Δ_{i, j}= 0.Then there are three slightly more complicated cases.

1.

*r*_{i}>*r*_{j}: bottom of*i*-th bowl gets stuck somewhere between the top and the bottom of*j*-th,touching it's sides. From the similarity of some triangles we get that .

2.

*R*_{i}≤*R*_{j}: top of*i*-th bowl gets stuck somewhere between the top and the bottom of*j*-th,touching it's sides. From the similarity of some triangles we get that .

3.

*R*_{i}>*R*_{j}: sides of*i*-th bowl touch the top of*j*-th in it's upper points. Then .Note that, for example, cases 1 and 2 do not exclude each other, so the final value of Δ

_{i, j}is equal to the maximum of the values, computed in all three cases.Note that if the calculated value of Δ

_{i, j}is negative, the result should be 0. Thanks to adamax for pointing it.
It seems that it's case 2, but the formula will give a wrong answer.

_{ij}.R_{i}≤r_{j}_{i, j}is negative, the result should be 0.R_{i}≤r_{j}: bottom ofi-th bowl reaches the bottom ofj-th. Then Δ_{i, j}= 0.