Loop over all those segments whose start point is less than the end point of current segment
while seg >= arrived : NEW_LINE INDENT p += 1 NEW_LINE if p >= n : NEW_LINE INDENT break NEW_LINE DEDENT arrived = points [ p ] [ 0 ] NEW_LINE DEDENT i = p NEW_LINE