I Have Implemented the same Concept as per the Example it working well But pass Only one Test Case
There are two changes : Change all instances of int to long long int
Also change the condition expression in function isPossible to
if (x*mid <= m + (n - mid)*y)
return true;
Hope it Helps.