Binary Search Template for C++

 Binary Search Template for C++


#define int            long long int
int low=0,high=1e13,mid;
int ans=1e18;
while(low<=high){
    mid=low+(high-low)/2;
    if(helper(v,mid,m)){
        ans=min(ans,mid);
        high=mid-1; 
    }
    else low=mid+1;
}
cout<<ans<<endl;

Post a Comment

0 Comments