Help in Maintenance Planning (

Hi! I recently tried to solve Maintenance Planning problem, but I cannot figure out how to resolve the last subtask. Basically, my solution is a dp[i] that represents the minimum price that I have to spend in order to have the machine sold in year i. My reccurence relation is dp[i] = min(dp[i - j] + C + m1 + m2 + … + mj - pj) where j is from [1, d]. The problem is that I will get TLE for last subtask, obviously, and I cannot figure out how to approach it. Thus, I will be grateful if you can guide me with some hints :smiley:
P.S.: I figured out that “C + m1 + … + mj - pj” is a constant but I cannot see how to use it