TLE for O(log(mn))


#1
int n = A.size(), m = A[0].size(), l = 0, r = m * n - 1;
if(m*n==1)
    return A[0][0]==B;
while (l<=r){
    int mid=(l+r)/1;
    if (A[mid/m][mid%m]==B)
        return 1;
    else if(A[mid/m][mid%m] < B)
        l = mid + 1;
    else r = mid-1;
}
return 0;

Why is it giving TLE for the above code


#2

mid = (l+r)/1; --> incorrect
mid = (l+r)/2; --> correct

I suggest you should use
mid = l + (r-l)/2;
it will not overflow.


#3

Thanks, corrected it