Given a stream of token probabilities, write an efficient algorithm to implement top-p nucleus sampling.