Plz check the code

working for 50% test cases

#include<bits/stdc++.h> using namespace std; bool alloc(int n,int nc,int mid,int x,int y){ if((mid*x)<=(nc+(n-mid)*y)){ return true; }else{ return false; } } int main() { int n,m,x,y; cin>>n>>m>>x>>y; long long int s=0; long long int e=n; long long int mid; long long int ans=INT_MIN; while(s<=e){ mid=(s+e)/2; //cout<<“mid”<<mid<<endl; if(alloc(n,m,mid,x,y)){ ans=max(ans,mid); s=mid+1; }else{ e=mid-1; } } cout<<ans; }

Make all your variables long long int in the alloc function as well.

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.