Facing TLE In Test Case Number 4

Could You Please Check My Code Where I am going wrong I am facing TLE in Test Case Number 4

Please Check the Code Below:

Okay Let me check it

Instead of doing a three D dp you can do a 2- D dp. You can consider this question similar to the coin change problem where you have to make N rupees with the help of X denomination of coins. Take red and blue balls independently and answer the minimum of both of them.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.