Doubt in question - please reply ASAP

Sir, i am trying a question on codechef. I have written the code which works perfectly on custom input, but gives a wrong answer. I do not want the solution of the question. But I want to know what am i doing wrong. Please point out my mistake.

Link to Question:
https://www.codechef.com/START1C/problems/COUPON2

Link to my code:

Hello @gaurisha i can see this question is of Dynamic programming and you are not using that.
have you come up with any other approach?please explain that.

sir i have used brute force approach

That is why you are not able to submit.
check this editorial:

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.