Optimal weighting of speed and accuracy in a sequential decision-making task