A minimax near-optimal algorithm for adaptive rejection sampling