Provably Optimal Reinforcement Learning under Safety Filtering