Giving Tle with feq test cases

Have memoized it , still giving TLE

sol : https://ide.codingblocks.com/s/313728

qn M-CANDIES AT-CODER https://atcoder.jp/contests/dp/tasks/dp_m

Your top down code is correct but Try to solve it using bottom up.

this question require complexity O(n*k)
and your code is of O(n * k * k)