For hotel Bytelandia

My programs executes successfully in Dev c compiler… But shows RUNTIME error while in this codechef compiler… Plz help me track d problem for my prograam… The program goes as follows…

   #include<stdio.h>

   void performer(int arrival[], int departure[], int);
   
   int main()  {
       
       int n,guest,i;
       int arrival[100],departure[100];
        
    //   printf("\nEnter the number of test cases: ");
       scanf("%d", &n);
       
       while(n--)  {
                   
    //    printf("\nEnter the number of guests: ");
        scanf("%d", &guest);
                   
    //    printf("\nEnter the arrival time of guests: ");
        
        for(i=0; i<guest; i++) 
            scanf("%d", &arrival[i]);
            
    //    printf("\nEnter the departure time of guests: ");
        
        for(i=0; i<guest; i++)
           scanf("%d", &departure[i]);
           
        performer(arrival,departure,guest);
 }    
        return 0;
 }                                 
       
        void performer(int arrival[], int departure[], int guest)  {
            
         int max, min,i,j,replica,maxi;
         static int count[100];
          
         min=arrival[0];
         
         for(i=0; i<guest; i++) {
            if(arrival[i]<min)
                min=arrival[i];
       } 
       
         max=departure[0];
         
         for(j=0; j<guest; j++) {
            if(departure[j]>max)
                 max=departure[j];      
       }           
                    
          replica=min+1;
         
          while(replica<=max) {
         
         // printf("%d ", replica);                                
         for(i=0; i<guest; i++) {
                    
           if(replica>=arrival[i] && replica<departure[i]) 
                 count[replica]++;
       
    }      replica++;
 }       
        
    /*    for(i=min; i<max; i++) 
            printf("%d  ", count[i]);  */
            
        maxi=count[0];
        
        for(i=min+1; i<max; i++) {
            if(maxi<count[i])
               maxi=count[i];       
       }           
          printf("%d", maxi);
             
        for(i=min+1; i<max; i++)
            count[i]=0; 
            
         printf("\n");       
   }

http://www.codechef.com/problems/HOTEL for those who want to help and who don’t want search on the site.

Your array count is too small:
1<min<=max<=1000, but you have declared int count[100]

1 Like