Greedy approach to find maximum product $P = (A-k_{1})*(B-k_{2}).$

22 Views Asked by At

Suppose you are given two integers $A$ and $B$; $A \leq B$. I have to calculate the maximum possible value of the expression $P = (A-k_{1})*(B-k_{2}).$ Here $k_{1}$ and $k_{2}$ both are variables but its not guaranteed that $k_{1}$ or $k_{2}$ = $0$. Is there any greedy approach to choose $k_{1}$ and $k_{2}$ so that it maximises $P$ ?

1

There are 1 best solutions below

1
On BEST ANSWER

Since you mentioned that k1 and k2 can not be always 0, I want to point out that P is a strictly decreasing function as we increase k1 and k2. If A < B then I suggest that you try to keep A as large as possible and try to decrease B.