Code only passing two test cases even if I am using greedy algorithm

Link to my Code - https://ide.codingblocks.com/s/194631

Kindly help me to rectify what I am missing in my code to pass all the test cases?

Sorry , I am using Dynamic Programming.

@7nishit
check this line of ur code->