TLE in LCH15CD

dynamic-programming
lunchtime
python
tle

#1

I implemented the solution in Python using Dictionary but I got TLE in the last subtask. Link of my solution.

I have used dynamic programming. I tried mapping the n-dimensional tuple to a value using in-built dictionary.

Please help why I am getting TLE.

Please Help is it due to python or due to dictionary or n-dimensional tuple or some optimization mistake ??