An Optimal Algorithm for Monte Carlo Estimation