For example, 35ml needed where only 16ml and 10ml available. 35ml can be made with (3pcs of 16ml) = 48, (4pcs x 10ml) = 40 or (1 x 16ml, 2 x 10ml) = 36 but the optimal one is (1 x 16ml, 2 x 10ml) because there is only 1 = 36-35 space unlike others.
Update:
I was trying to use linear programming which may help to find x and/or y (finding the quantity) based on constraints but it's like I find it difficult to implement.
Constraints are:
Let z be the number of space
X and/or Y to be the quantity
16x + 10y >= 35
x>=0
y>=0
outcome = 16(1) + 10(2) >= 35
Let z be the excess
and x and y be the number of 16ml and 10ml bottles. So they are defined as integers
Let A be the desired Amount. So the optimization problem is
$Min$ $ z= 16x + 10y - A$ such that $x,y,z \ge 0$
$x,y$ are integers