WINNIG CB SHOLARSHIP

my code is getting wa in last 3 test case,
can u please help me out

exactly what I m doing wrong

#include<bits/stdc++.h>
using namespace std;

int main()
{

int n,m,x,y;
cin>>n>>m>>x>>y;
int i=0,j=n,ans;
while(i<=j)
{
    int mid=(i+j)/2;
    int totalcoupons=m+(n-mid)*y;
    int totalcouponsrequire=mid*x;
    int flag=0;
    if(totalcoupons>=totalcouponsrequire)
    flag++;
    if(flag)
    {
        //can be possible aage bhi check kr skte hai
        i=mid+1;
        ans=mid;
    }
    else
    {
        //more coupon need less student get scholarship
        j=mid-1;
    }
}
cout<<ans<<endl;

}