Reduce the difference between three numbers

268 Views Asked by At

Is there a way to know the maximum possible reduction between three numbers $(a>b>c)$, so that all three numbers are closer to each other but with the constraint that combined subtraction allowed from the three numbers is limited to a number $'M'$ and combined addition allowed from all three numbers is limited to a number $'N'$.

So for an easy example, if $a=9, b=6, c=5$ and combined addition allowed $(N)=7$ & combined subtraction allowed $(M)=0$ then the three numbers can become $a'=(9+0)=9, b'=(6+3)=9, c'=(5+4)=9$. Which is the closest they can get given the constraints $\rightarrow$ 3 was added to $'b'$ and 4 to $'c'$ making the total $(N)=7$.

Can there be a general way to do this for any $(a,b,c)$? Or some analytical formula which can give maximum bound all three numbers will remain within given $M \,\, \& \,\,N$.

1

There are 1 best solutions below

2
On BEST ANSWER

You can solve the problem via linear programming as follows. Let $M_a, M_b, M_c$ be the amounts added, and let $N_a, N_b, N_c$ be the amounts subtracted. Let $U$ represent $\max(a',b',c')$ and $L$ represent $\min(a',b',c')$. The problem is to minimize $U-L$ subject to: \begin{align} L \le a + M_a - N_a &\le U \\ L \le b + M_b - N_b &\le U \\ L \le c + M_c - N_c &\le U \\ M_a + M_b + M_c &\le M \\ N_a + N_b + N_c &\le N \\ M_a, M_b, M_c &\ge 0 \\ N_a, N_b, N_c &\ge 0 \\ \end{align}