1 <i <j wiyi) respectively.
This observation allows us to generalize to
gi(y) = max {gi+1(y), gi+1(y- wi+1) + pi+1}
Where gn(y) = 0 for all y > 0 for all the n's higher than the n we are going to, the values are 0, i.e., we do not choose them
and gn(y) = - for all y < 0 if there is no more capacity left in the sack, we make the solution so small it cannot be the chosen one