I was solving the question from recent contest Starters 13
I tried it to do it using Binary Search but got WA while brute force worked can any one tell me why this happened ??
Here is my code
bool is ( int P , int a , int ar , int mid , int midp ) {
int tr = mid * ( ar * a + midp ) ;
if ( tr > P ) return 0 ;
return 1 ;
}
void Go () {
int P = 0 , a = 0 , b = 0 , c = 0 , x = 0 , y = 0 ;
cin >> P >> a >> b >> c >> x >> y ;
int bb = 0 , cc = 0 ;
int low , high ;
low = 0 , high = P ;
while ( low <= high ) {
int mid = low + ( high - low ) / 2 ;
if ( is(P,a,x,mid,b) ) {
bb = mid ;
low = mid + 1 ;
} else {
high = mid - 1 ;
}
}
low = 0 , high = P ;
while ( low <= high ) {
int mid = low + ( high - low ) / 2 ;
if ( is(P,a,y,mid,c) ) {
cc = mid ;
low = mid + 1 ;
} else {
high = mid - 1 ;
}
}
cout << max ( bb , cc ) << '\n' ;
}