Scaling LLM Inference with Optimized Sample Compute Allocation