Question link : https://www.codechef.com/problems/BUYING2
Solution Link: https://www.codechef.com/viewsolution/23407462
Question link : https://www.codechef.com/problems/BUYING2
Solution Link: https://www.codechef.com/viewsolution/23407462
Your approach is correct. It seems you are printing extra stuff like “Enter number of test cases: Enter no. of notes, price of sweet: Enter values of notes:”. Those lines are not needed.
I modified your solution a little and it got accepted. See here - https://www.codechef.com/viewsolution/23454337.