Proof by contradiction for greedy algorithms
Just think like this. Without loss of generality, assume

$\begin{equation*}
   \dfrac{v_1}{w_1} &gt; \dfrac{v_2}{w_2} &gt; \dotsb &gt; \dfrac{v_n}{w_n}
\end{equation*}$

(item types with same $v_i/w_i$ can be merged, it doesn't matter in the end).

Let ALGs choices be $p_1, p_2, \dotsc, p_n$, OPTs choices be $q_1, q_2, \dotsc, q_n$.

Assume ALG doesn't give an optimal solution, so $\mathbf{p} \ne \mathbf{q}$. As they are different, there is $i$ such that $p_k = q_k$ for $1 \le k \le i$ and $p_i \ne q_i$. By the way ALG works, it adds as much of $i$ as it possibly can, so $p_i &gt; q_i$.  What OPT looses by this against ALG on $i$ is $(p_i - q_i) \cdot v_i / w_i$, and it more than makes up the loss by adding $(p_i - q_i)$ weight of items that are all worth less per weight than $i$. That is impossible.