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 = midx, 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
Problem cb scholarship 2
@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 = midx, 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.