My code is passing 3 test cases but not passing the rest 3? Although I have used the same logic explained in video

Look out for integer overflows.

Can you tell what is integer overflow and how to check for it?

Expressions like,

mid*x, m+(n-mid)*y, ...

won’t fit in the ‘int’ range, so you need to use ‘long long int’ for these.

I tried typecasting the expression to long long int,but still my code is not givng all test cases right? https://ide.codingblocks.com/s/332985

This will still overflow, if you want the result to be evaluated as long long int, then at least one the terms in multiplication should be long long int.

The easiest way right now is to change all int to long long.

Hey @isingh
Replace line 5 by

if((1ll*mid*x)<=(m+1ll*(n-mid)*y))

Here 1ll (This is LL in small case) stands for a long long number with value 1.
So multiplying it with 1 will make multiplication to hold bigger value and will not overflow :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.