Why am i getting wa on this. http://www.codechef.com/RCSN2015/problems/RECCKT. Please help.

#include<stdio.h>
main()
{
long long x,j,t,n,a[100000],i,r[10000],z[100000],big;
scanf("%lld",&t);
while(t–)
{
scanf("%lld",&n);
for(i=0;i<n;i++)
scanf("%lld",&a[i]);
x=0;
for(i=0;i<n;i++)
{

		    for(j=i+1;j<n;j++)
		    {
		    	r[x]=a[j]-a[i];
		    	x++;
	    		big=r[0];
	    	}
	    	for(j=0;j<=x-1;j++)
	    	if(big<r[j])big=r[j];
	    	z[i]=big;
	    }    
	    big=z[0];
	    for(i=0;i<n;i++)
	    if(big<z[i])big=z[i];
		printf("%lld\n",big);
	}
	return 0;
}

Simple Solution is:

max_difference=INT_MIN
smallest=a[0]
for(i=1;i<N;i++)
    if(a[i]<smallest)
         smallest=a[i]
    else if(max_difference<a[i]-smallest)
         max_difference=a[i]-smallest
print max_difference

Hope you got it!

1 Like