def search(activity, current):
    """Find the previous compatible activity using binary search. """
    mini = 0
    maxi = current - 1
    while mini <= maxi:
        avg = (mini + maxi) // 2
        if activity[avg].finish <= activity[current].start:
            if activity[avg + 1].finish <= activity[current].start:
                mini = avg + 1
            else:
                return avg
        else:
            maxi = avg - 1
    return None