What is wrong with my code for CHPINTU in C

#include <stdio.h>
#include<stdlib.h>

int main(){
int number_of_test_cases,number_of_baskets,number_of_fruits,min,index;
scanf("%d",&number_of_test_cases);
for(int i=0;i<number_of_test_cases;i++){
scanf("%d %d",&number_of_baskets,&number_of_fruits);
int* type = malloc(number_of_basketssizeof(int));
int
price = malloc(number_of_basketssizeof(int));
int
a = malloc(number_of_fruits*sizeof(int));
for(int k=0;k<number_of_baskets;k++){
scanf("%d",&type[k]);
}
for(int k=0;k<number_of_baskets;k++){

				scanf("%d",&price[k]);
		}

     for(int k=0;k<number_of_fruits;k++){
        a[k]=0;
    }
   for(int k=0;k<number_of_baskets;k++){
		 //index = type[k] - 1;
       a[(type[k]-1)]+=price[k];
   }

	 for(int k=0;k<number_of_fruits;k++){
		if(a[k]>0){
			min=a[k];
			break;
		}
	 }
   for(int k=1;k<number_of_fruits;k++){
       if(a[k]<min&&a[k]!=0)
        min=a[k];

   }
   printf("%d\n",min);

}

return 0;

}

Given above is my code for CHPINTU for MARCH20B contest. It is displaying wrong answer after submitting it. But I am not able to figure out where it is going wrong as it is giving the test case answer correctly along with some more cases that I thought of.

So could somebody tell me what is the error?

Please either format your code or provide link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

1 Like

Solution for reference

https://www.codechef.com/viewsolution/30518054

well first of all assign a huge value to min.
Since you did not assign it any value it will have garbage value that can be smaller than the input value.

1 Like

Thanks Man!!! It has been now accepted.

1 Like