Given:

TargetWeight

Two different Weights (as many as you wish)

Question:

Using either one of the weights or both, what is the closest weight you can get to the target weight?

Requested output:

The closest weight and a number of each weight was used.

For example: for given TargetWeight of 230 grams and two weights of 170 grams and 40 grams. Which combination of these weights will give the closest to 230 grams?

I am struggling already for two days. Any help will be appreciated.

Thanx.