Doubt in Watching CPL regarding complexity (Weak test cases)

Here, In WIPL I used subset-sum DP in the do-while loop, which means worst-case complexity would be k^3, and k = 4000, so the answer should be TLE, But I got AC.

It may be due to weak test cases or some other reason ??

This is my AC solution