Winning cb scolarship

All test cases are not passing
#include
using namespace std;
bool scolarship(int n,int m,int x,int y, int mid)
{
if(mid*x<=m+(n-mid)*y)
return true;
else
return false;
}
int main(){
int n, m, x, y;
cin>>n>>m>>x>>y;
int s=0;
int e=n;
int mid,ans;
while(s<=e){
mid=(s+e)/2;
bool isPossible = scolarship(n,m,x,y,mid);

    if(isPossible){
        ans=mid;
        s=mid+1;
    }
    else
        e=mid-1;
}
cout<<ans;

return 0;}

Hello @ayu2321,

Problem:
Your code is failing for the constraints given in the question.
x*mid can be a value greater than the range of int.

Solution:
Change the data type of mid to long.

Hope, this would help.
Give a like if you are satisfied.

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.