Why can/should we use 5 instead of 10? Problem:

A pharmacy has a uniform annual demand for 200 bottles of a certain antibiotic. It costs \$10 per year for a storage place for one bottle, and $40 to place an order. How many times during the year should the pharmacy order the antibiotic in order to minimise total cost?

$ $

Example 1: If you use 4 orders of 50 bottles each you need 50 storage places.

Cost of ordering is $4(40) = 160$
Total Cost is $4(40)+50(10)= 660$

Example 2: If you use 10 orders for 20 bottles each, you need only 20 storage places, but it costs more to order:

Cost of ordering is $10(40) = 400 > 160$
Total Cost is $10(40)+20(10) = 600$
It seems that we must minimize
$$C(x,y) = 10x+40y$$
s.t. $200=xy$
I can change it to one variable, use Lagrange or something.
My professor gave this hint:

Use \$5 per storage place instead of $10. The reasoning is that some bottles will get used right away, and some need to be stored the full time.

Something like 5 is the median of 0 and 10.
So apparently
$$C(x,y) = \color{red}{5}x+40y$$
Why?
Note: The minimisations will be different:
http://www.wolframalpha.com/input/?i=Minimise+5x%2B40(200%2Fx)
http://www.wolframalpha.com/input/?i=Minimise+10x%2B40(200%2Fx)
 A: Assuming your inventory is depleted linearly (at a constant rate), you will make an order, which will put $x$ bottles in your inventory, it will deplete down to 0, and you reorder, to fill your inventory back up to $x$ (the order is immediately filled), and the cycle repeats.
When the inventory is full, you're paying to store $x$ items, but when it starts getting low, you're only paying to store fewer items.
Since the inventory drops at a constant rate, the average number of bottles of pills in your inventory at any given time will be half of x. Think about it: for the first half of the time you're using an inventory it's above half capacity, then the second half is below half capacity (and decreasing in a straight line). So, on average, the inventory cost is actually $10\left(\frac{x}{2}\right)$, or $5x$.
Your total cost is $C(x,y) = 5x + 40y$ because you have to pay the average storage cost (\$5) for each item in the inventory and pay \$40 for each order you make. You'll make $\frac{200}{x} orders, so you just need to minimize
\begin{align}
C(x) = 5x + \frac{8000}{x}
\end{align}
so that
\begin{align}
C'(x) = 5 - \frac{8000}{x^2}
\end{align}
Then we can minimize as
\begin{align}
5 - \frac{8000}{x^2} &= 0
\\5 &= \frac{8000}{x^2}
\\5x^2 &= 8000
\\x^2 &= 1600
\\x &= 40
\end{align}
so you should make 5 orders of 40 items each per year.
A: If you buy as soon as you completely run out of inventory (you can prove that it is always better to do this, since orders take no time), then your number of bottles stored in each cycle can be interpolated as $N-200t$, where $N$ is the order size and $t$ is the time since the last order in years. The average of this over an order period is $N/2$. You can check by integrating if you want, or you can just think about the area of a triangle. Ultimately, over one order period you wind up paying $N/2$ times $\$10$ times the time in between orders (in years). Adding up the cost over a full year cancels out the factor of the time, leaving a total cost of $\$5N$ for the storage cost. 
The actual number may be slightly different from this. There is a correction associated to the discreteness of the removal of the bottles from storage, and when exactly that takes place. (The formulation above turns the number of bottles into a continuous variable which decreases continuously over time, to make the calculation easier.) There could be another correction if the optimum value of $N$ that we compute here does not evenly divide into $200$. (With these numbers it actually does, but one can easily tweak the numbers to make this not happen.) But these are small corrections, and are probably smaller than more fundamental problems with the model (such as the assumption that orders are paid for and then instantaneously delivered and the assumption that the orders come at exactly uniform times).
