Sir, query in Subset sum to target

I have solved the problem successfully, however when I tried top down approach, it gave TLE in testcases 1 and 2, also when used bottom up DP with bool datatype, it gave TLE too. It works for the current version of the code.

I am unable to figure out what works and what caused the previous versions to give TLE?

Can you send me the code so that I can check it out.

Top Down Approach link(TLE version):

Top Down with bool dp table(WA in one case):

And the one with bottom up approach, I figured it out.