Algorithm 24 - One-dimensional knapsack function - Kucharczyk, Jerzy (1972)