There is a cuboid. Assume that the width of the base is X. Then the Length of the base should not exceed (A−X) and the Height should not exceed (B−X). Also The Volume should be maximum. you are given the two integers A and B,find an integer X such that the Volume is maximum.find minimum X.
Note: All dimensions should be strictly positive integers.
Constraints
1≤T≤500000(Number of testcases)
2≤A, B≤50000(Integers only)
output in a single line the value of X and the maximum volume.
So, it seems fairly straightforward that we have to differentiate (A-X)*(B-X)*(X) and equal to 0 will give us the quadratic equation, and we have to find the minimum positive X and calculate the volume. But, my code is giving WA for some cases.
You say a and b can be as high as 50000 and at one point you are calculating a*b. If they are both 50000 then the result is just beyond the range of a 32-bit signed int. Make a and b long long.