3 ms·
$0.00 is always achievable (choose nothing), and negative values are never achievable. Is $0.01 achievable? Well, take all items, subtract their price from $0.
by H8crilA 5y ago
$0.00 is always achievable (choose nothing), and negative values are never achievable.
Is $0.01 achievable? Well, take all items, subtract their price from $0.01 and see if any of the results are achievable. If so, $0.01 is achievable.
Repeat for $0.02, $0.03, ... This works because by the time you're processing $X you already know the answers to all values smaller than $X (and no item has a negative price).