Given 4 quarts = 1 gallon => 0.4 gallon = 1 quart
The key information here to understand is that you can buy gallons in whole numbers only for $18/gallon. If you have, say 5.4 gallons you’ll have to buy 6 gallons at $18/gallon which totals 6x18 = $108. However, here you can use the 0.4 gallon to buy a quart at $12/quart so now you’ll need to pay 5x18 + 1x12 = 90 + 12 = $102. Clearly using quarts and gallons together here is cheaper.
Now back to the question:
We have a 3 gallon mixture, which has 3 parts blue and 2 parts white
This means our 3 gallon mixture is a total of 5 parts => 1 part = 3/5 gallon each
So 3 parts blue is: 3x(3/5) = 9/5 gallons => 1.8 gallons => 1 gallon, 2 quarts
And 2 parts white is: 3x(2/5) = 6/5 gallons => 1.4 gallons => 1 gallon, 1 quart
So for the blue part, we can buy 1 gallon at $18/gallon and 2 quarts at $12/quart => 18 + 12*2 => $42
However, if we simply buy 2 gallons instead of this, we’ll get it at 2*($18/gallon) => $36
This is cheaper, so we’ll buy 2 gallons only for the blue part
Now for the white part: We can buy 1 gallon at $18/gallon and 1 quart at $12/quart => $30
Hence, minimum amount needed: $66