def mem_binary_search(arr, time, return_ind=False):
    """
    Performs binary search on array, but assumes that the array is filled with tuples, where
    the first element is the value and the second is the time. We're sorting utilizing the time field
    and returning the value at the specific time.
    Args:
        arr: sorted array with (val, start_time)
        time: the time that we are looking for
        return_ind: If True, return the index corresponding to time in arr
    Returns:
        the value that took place at the given time
    """
    # if len(arr) == 0 or time < arr[0][1]:
    #     return None
    start, end = 0, len(arr)
    while (end > start+1):
        mid = (end + start) // 2
        if time >= arr[mid][1]:
            start = mid
        else:
            end = mid

    if return_ind:
        return start
    else:
        return arr[start][0]