Puzzle: Maximum amount of rice Farmer Felix has just had a bountiful harvest with 1 ton of rice, and now he wants to sell all of it. Before getting his rice to the market, his rice needs to go through inspection. Unfortunately, the inspector is a greedy tyrant, and he wants a part of Felix's harvest. The inspector's price is as follow:

*

*The first inspection costs all the rice.

*If Felix gives the inspector x ton of rice, then the next inspection costs x less.

For example, if the inspector is given 0.2, 0.3, 0.5 ton portions in that order, then finally the total amount of rice gets to the market is:
$$0.2\times0 + 0.3\times0.2 + 0.5\times(0.2 + 0.3) = 0.31$$
What is the maximum amount of rice Felix can get to the market (given that the inspector doesn't mind even when he's requested to inspect infinite times)?
 A: If Felix takes rice to the inspector $n$ times with $a_i$ tons of rice at $i$-th step, then the rice that goes to the market is given by the following formula:$$
x = \sum_{i=1}^n a_i\cdot \big(\sum_{j=1}^{i-1} a_j\big)=\sum_{i=1}^n\sum_{j=1}^{i-1}a_i\cdot a_j = \frac{(a_1+a_2+\dots+a_n)^2-a_1^2-a_2^2-\dots-a_n^2}{2}=\frac{1-\sum a_i^2}{2}.
$$ The last equality holds since $\sum a_i=1$. By picking $n$ to be arbitrarily large and $a_i$ to be arbitrarily small, you can see that the amount of rice taken to the market can be made arbitrarily close to $0.5$ tons. Also by the formula you can see that there is no way to take more than $0.5$ tons to the market.
In your example, you made a mistake since $0.2\times 0+0.3\times 0.2+0.5\times (0.2+0.3)=0.31$, not $0.51$.
Edit: The $0.5$ bound also works if you allow Felix to go to the inspector infinitely many times. Say $\sum_{i=1}^\infty a_i=1$ (with, of course, $a_i>0$). Then $\sum_{i=1}^\infty a_i^2$ is also convergent, thus the above formula still holds.
A: I haven't been able to solve it yet. Below is my thoughts about the puzzle. I hope my English is enough to convey my thinking.
At first, I intended to let the inspector to accept a limit amount of times only (2, 3, 4,..., n inspections) but it escalates quickly into finding maximum value of a multi-variable function. So, maybe it'll be a question for another time.
I've been thinking about the answer, but it turns out to be harder than I imagine it to be. Initially, I let Felix giving rice according to f(x) = x, where:
$$ \int_0^{1/2}{xdx} = 1 $$
Felix gives a tiny bit of rice xdx at a time and 1 is the total amount of rice Felix has after the harvest. So the amount of rice to the market after all the inspections is:
$$ \int_0^{1/2}{x({\int_0^xudu}) dx} = \int_0^{1/2}{x\frac{x^2}{2}  dx} = \frac{1}{128}$$
where $${\int_0^xudu}$$ is the total amount of inspected rice at some point (inspection cost discounted) and $$ xdx $$ is the tiny amount of rice Felix is giving at some instant.
Now, when the idea of calculus first rose in my mind, I thought "If I make Felix inspect rice in an increasing amount, he'll get more rice in the end." But calculation proved otherwise, 1/128 is definitely less than 0.51. Am I doing something wrong here?
Also, what I'm curious is what function f(x) will give the maximum amount of rice, thus I try to generalize it as:
$$ \int^a_b{f(x)dx} = 1$$
Also, the amount of rice that gets to market:
$$ \int^a_b{f(x)({\int^x_b{f(u)du})}dx}$$
The train of reasoning is similar to above. And let's assume we can find F(x) such that the derivative F'(x) = f(x), then:
$$ \int^a_b{f(x)({\int^x_b{f(u)du})}dx} = 
 \int^a_b{f(x)(F(x) - F(b))dx}$$
Since F(b) is a constant, and the integration of f(x) over (a, b) is 1, I finally arrive at:
$$\int^a_b{f(x)F(x)dx} - F(b)$$
which is not helpful at all. Could you give me some clues about what to do next?
