Bytelandian gold coin - wrong answer why?

Here is my code, any help??

#include <stdio.h>
int main(){
int i, num, a, b, c;
scanf("%d", &num);
long int coin[num], k[num];
for(i=0; i<num; i++) scanf("%d", &coin[i]);
for(i=0; i<num; i++){
a=(int)coin[i]/2;
b=(int)coin[i]/3;
c=(int)coin[i]/4;
if((a+b+c)>coin[i]) k[i]=a+b+c;
else k[i]=coin[i];
}
for(i=0; i<num; i++) printf("%d\n", k[i]);
return 0;
}

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.

1 Like