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

SPOJ AMR10G getting WA. Any specific test cases?

$
0
0
#include<stdio.h>
int main()
{
    int n,k,T,i,x,x1,p,y;
    long long int arr1[2000],arr2[2000],min,t;
    scanf("%d",&T);
    for(x=0;x<T;x++)
    {
      i=0;
      scanf("%d%d",&n,&k);
      for(x1=0;x1<n;x1++)
      scanf("%lld",&arr1[x1]);

     //sort
   for(x1=0;x1<n;x1++)
   {
      p=x1;
      for(y=x1+1;y<n;y++)
      {
      if(arr1[y]<arr1[p])
      p=y;
      }
     t=arr1[x1];
     arr1[x1]=arr1[p];
     arr1[p]=t;
   }

     t=0;
     while((i+k-1)<n){

     arr2[i]=arr1[i+k-1]-arr1[i];

     t++;
     i++;
     }

 min=arr2[0];
   for(x1=0;x1<t;x1++)
   {
   if(arr2[x1]<min)
   min=arr2[x1];
   }
printf("%lld\n",min);
}
return 0;
}

Viewing all articles
Browse latest Browse all 40121

Trending Articles



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