Problem cb scholarship 2

import java.util.;
public class Main {
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
int n = cin.nextInt(), m = cin.nextInt(), x = cin.nextInt(), y = cin.nextInt();
int low = 1, high = n,ans = 0;
while(low<=high){
int mid = (low+high)/2;
int req = mid
x, avail = m + (n-mid)*y;
if(avail>req){
low = mid +1;
ans = mid;
}else if(avail<req){
high = mid -1;
}else if(avail == req){
ans = mid;
low = mid + 1 ;
}
}
System.out.print(ans);
}
}====== still not getting all test cases right

@AbhishekAhlawat1102
take values in long because the product of integer can go out of range

@AbhishekAhlawat1102
import java.util.;
public class Main {
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
long n = cin.nextLong(), m = cin.nextLong(), x = cin.nextLong(), y = cin.nextLong();
int low = 1, high = (int)n,ans = 0;
while(low<=high){
int mid = (low+high)/2;
long req = mid
x, avail =(m + (n-mid)*y);
if(avail>req){
low = mid +1;
ans=mid;
}else if(avail<req){
high = mid -1;
}else if(avail == req){
ans=mid;
low = mid + 1 ;
}
}
System.out.print(ans);
}
}

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.