#include
using namespace std;
bool isvalid(int x,int tt,int children)
{
while(children–)
{
tt=tt-x;
}
if(tt<0)return false;
else return true;
}
int main()
{
long int n,m,x,y;
cin>>n>>m>>x>>y;
int s=1,e=n,tt=m+y,ans;
while(s<=e)
{
int mid;
mid=s+(e-s)/2;
tt=m+(n-mid)*y;
if(isvalid(x,tt,mid))
{
ans=mid;
s=mid+1;
}
else
{
e=mid-1;
}
}
cout<<ans;
return 0;
}
Doubt in winning cb scholarship(3 test cases are being passed out of 6)
Yash, you are using a little wrong approach in the program, plz refer to the online video hint given in online lecture on it.