How to solve class assignment problem

I have solved the problem using this code: https://pastebin.com/btAZcJnh

hi prajwal
your code is giving TLE so you are supposed to optimize it and the optimization to the above problem can be done through dp

try doing through dp. if you still don’t get it message me

But I havent reached the dp lecture yet. So I guess I’ll move on for now.