Given a set of numbers (negative or positive), and a maximum weight w, find a subset that is maximal whose sum is less than w
This problem can be solved by a rather simple dynamic programming:

Given a set of numbers $\{a_1,\dots,a_n\}$, let $best(i, w)$ be the best solution using only a subset of the elements $a_i,\dots,a_n$ with a maximum value $w$, then $$best(i,w) = max(a_i + best(i+1,w-a_i), best(i+1,w))$$
With boundaries conditions $best(n + 1,w) = -\infty$ for any $w &lt; 0$, 
and $best(n + 1,w) = 0$ otherwise.

Note that this problem is NP-hard because it solves the partition problem, in particular the running complexity of the above program depends on the given numbers, and can be exponential in the size of the input in the worse case.