I am failing 3 test cases

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

public static void main(String[] args) throws IOException {
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer st=new StringTokenizer(br.readLine());
	int N=Integer.parseInt(st.nextToken());
	int M=Integer.parseInt(st.nextToken());
	int X=Integer.parseInt(st.nextToken());
	int Y=Integer.parseInt(st.nextToken());
	System.out.println(Search(N, M, X, Y));

}public static int Search(int N,int M,int X,int Y) {

int ans=0;
int low=0;
int high=N;
while(low<=high) {
	int mid=low+(high-low)/2;
	if(mid*X<=M+((N-mid)*Y)) {
		low=mid+1;
		 ans=mid;
	}else {
		high=mid-1;
	}
}
return ans;

}

}

Please tell me why i am failing test cases

convert N M X Y int to long

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

public static void main(String[] args) throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer st = new StringTokenizer(br.readLine());
	long N = Long.parseLong(st.nextToken());
	long M = Long.parseLong(st.nextToken());
	long X = Long.parseLong(st.nextToken());
	long Y = Long.parseLong(st.nextToken());
	System.out.println(Search(N, M, X, Y));

}

public static long Search(long N, long M, long X, long Y) {

	long ans = 0;
	long low = 0;
	long high = N;
	while (low <= high) {
		long mid = low + (high - low) / 2;
		if (mid * X <= M + ((N - mid) * Y)) {
			low = mid + 1;
			ans = mid;
		} else {
			high = mid - 1;
		}
	}
	return ans;
}

}