Learning the Optimal Policy for Balancing Short-Term and Long-Term Rewards