Binary search (like upper_bound in c++)