Simulation of a General equation I have solved a programming problem with a Equation. But can't simulate this equation briefly. Anyone can help me?
Question:
I have $n$ rubles initially. The cost of one plastic litre bottle, the cost of one glass litre bottle, and the money one can get back by returning an empty glass bottle are $a$, $b$ and $c$, respectively, where $1\leqslant a\leqslant10^{18}$, $1\leqslant c<b\leqslant10^{18}$. I need the maximum number of litre I can drink with my rubles.
Number of glass litre is $\dfrac{n-c}{b-c}$. 
Then total litre will be:
$t1 = \dfrac{n-c}{b-c}$
${n = n -(b-c)*t1}$
$t2 = \frac{n}{a}$
$ans = t1 + t2$
How this simulation has come? Can anyone please elaborate?
Example:
$n=10$
$a=11$
$b=9$
$c=8$
Answer will be $2$

Let $p$ and $g$ be the number of plastic and glass bottles purchased, respectively. Assume that you return all glass bottles.  Consider the problem of maximizing $p+g$ subject to linear constraints:
\begin{align}
a p + (b - c) g &\le n \\
p,g &\ge 0
\end{align}
For $(n,a,b,c)=(10,11,9,8)$ the optimal solution is $(p,g)=(0,10)$, but this solution is not implementable because you cannot simultaneously buy and return a glass bottle.
One way around this is to introduce a time index: for time $t=1,\dots,T$, let $p_t$ be the number of plastic bottles purchased, let $g_t$ be the number of glass bottles purchased, let $r_t$ be the number of glass bottles returned, and let $m_t$ be the amount of money available after purchases.  The new problem is to maximize $\sum_t (p_t + g_t)$ subject to:
\begin{align}
n &= a p_t + b g_t + m_t &&\text{for $t=1$} \\
m_{t-1} + c r_{t-1} &= a p_t + b g_t + m_t &&\text{for $t>1$} \\
r_t &\le g_t &&\text{for all $t$} \\
p_t, g_t, r_t, m_t &\ge 0 &&\text{for all $t$}
\end{align}
You will need to impose integrality of $p_t$, $g_t$, and $r_t$.  Without loss of optimality, you can assume $r_t=g_t$.
