Help needed in problem Discount on crackers DSA learning series

My solution is:CodeChef: Practical coding for everyone
I know my solution is wrong but how to identify it is graph problem the solution i had coded is giving right answer at sample test case but Giving WA while submitting .
Pls: Tell how to identify this problem can be solved by graph and approach to this problem
Thanks