TLE in Nuclear Reactors

CodeChef: Practical coding for everyone I am getting TLE for the big cases. Just by 0.01 second. Can I optimise the solution or would I need a new approach to solve this question.

To understand TLE, please read both - FAQ answer and/or my answer.