A correct answer, fifty seconds late
transcript
Your code is correct. The judge says Time Limit Exceeded. Why? The answer is right, but it arrives late. Late is a failure.
The code rebuilds the total each time. It starts from the first payment. It repeats finished work. The answer is right every time. Only the speed is wrong.
A busy day has a hundred thousand payments. That is five billion additions. One addition at a time. Count n times n plus one, over two. A short run confirms the formula.
A machine does a hundred million steps a second. Five billion steps take fifty seconds. The limit is two seconds. The judge stops the run at the limit. The verdict is Time Limit Exceeded.
Keep a running total instead. Add each payment once. A hundred thousand additions. Done at once. Each payment is added once. The answer is the same.
Count the steps first. Full breakdown in the lecture.