Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

Can u help me why this one is giving runtime error but giving the correct answer in my pc

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

int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}


main()
{
    int N,D;
    scanf("%d %d",&N,&D);
    int *L;
    L = (int*)malloc(N*sizeof(int));
    //int k[N];
    int i;
    for(i = 0;i<N;i++)
    {
        //k[i] = 0;
        scanf("%d",(L+i));  
    }
//  quicksort(L,0,N-1);
qsort(L, N , sizeof(int), cmpfunc);



    int count = 0;
    i = 0;
    while(i<N)
    {
                      if(L[i+1]-L[i]<=D && i<=N-2)
                      {i+=2;count++;}
                      else
                      i++;
    }

    printf("%d",count);

}

Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>