Here you converted coin[i] to a,b and c. These a,b and c can be further converted to coins. You have not considered those cases. For example if coin[i] is 60, you can first convert it into {30,20,15}(which gives you 65), now coin 30 can be converted as {15,10,7}(which gives you 32), 20 can be converted as {10,6,5}(which gives you 21), So you can get 68 by converting like this. Your program outputs 65 whereas 68 is the answer.