The problem statement does not say that the weights are sorted.
Weights are not necessarily sorted.
2 out of the 3 test cases are wrong! SMH
The right answer for
3 4 7
4 5 8
8
is 10 and not 9 like the test case seems to be looking for!
For test case #3 -
The right answer for
1 2 3
6 10 12
5
is 30 and not 22
My bad, I didn’t realize you can use an item only once.