This is a weird optimization problem I recently came across which I cannot solve.
Suppose we start off with an empty container of M&Ms. We take and add M&Ms to the container every year for n years. The number of M&Ms I take out each year, B, is always the same (think of it as a parameter). The number added in year i, A(i), is known (think of it as data) The net change in the number of M&Msfrom year i is dN(i) = A(i) - B If dN(i)< 0, I have an M&M "bank" I can go to cover my losses and so I can keep operating even with a deficit. The amount I owe the bank in year i, D(i) = D(i-1) + dN(i) (so it is a running total). If dN(i) > 0, then I apply any deficit I have with the bank, and if dN(i) > |D(i-1)|, i.e. the net positive number of M&Ms I get that year exceeds the amount of my deficit with the bank, I eat the extra M&Ms (yum).
The problem is: "Find the maximum value of B such that D(n) = 0" (i.e. what is the maximum number of M&Ms I can take out every year, so I have no deficit with the bank at the end of the n years)