java – How to run testing values to get to a result?

I have some variables like A B C and D. Each one of them have a specific value. And I have the variable X, which I inform it’s value like:
A has value of 20
B has value of 25
C has value of 27
D has value of 30.

Those values are static.

And I what’s to know how many As or Bs, etc that I need to get closest possible to X value. And X value can be any value the user inform. For example 135.
Then I want the application to calculate the best combination os A B C and D (not necessary to have them all) to get the closest possible to X number.