I am getting WA in AMR10G even though it passes the sample test cases,and I believe it is correct. Could someone guide me as to where I'm going wrong ? Atleast a tricky testcase which can help me debug is highly appreciated. This is the code I submitted:
#include<stdio.h>
#include<stdlib.h>
int compare(const void * a,const void * b){return(*(int*)a-*(int*)b);}
int main(){
int test;
scanf("%d",&test);
int t=0;
for(t=0;t<test;t++){
int n,k;
scanf("%d%d",&n,&k);
unsigned long long int *h=malloc(n*sizeof(unsigned long long int));
int i=0;
for(i=0;i<n;i++){scanf("%llu",&h[i]);}
qsort(h,n,sizeof(unsigned long long int),compare);
printf("%llu\n",(h[n-1]-h[n-k]));
}
return 0;}
Thank you.