3 out of 6 test cases are failed

public class WinningScholarship {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	Scanner s = new Scanner(System.in);
	int N = s.nextInt();
	int M = s.nextInt();
	int X = s.nextInt();
	int Y = s.nextInt();
	
	int lo = 0;
	int hi = N;
	int Max = 0;
	
	while(lo <= hi) {
		int mid = (lo+hi) / 2;
		
		if(check(mid, N, M, X, Y)) {
			lo = mid +1;
			Max = mid;
		}else {
			hi = mid - 1;
		}
	}
	System.out.println(Max);
	s.close();
	
}

private static boolean check(int z, int n, int m, int x, int y) {
	// TODO Auto-generated method stub
	return (z*x <= m + (n-z) * y);
}

Hey @danyalkhan8271 Use long instead of int for the values of n,m,x,y;

Thankyou for the response…

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.

1 Like

but i didn’t get replies on my next 2 doubts