I am getting tle and testcases failed..whats the mistake?

@garganshul151 constraints are large you have to use dp otherwise tle
dp soln for ref