Carvans | Please Help me with this

#include <stdio.h>

int main(void) 
{
	int a[5000],i,n,t,count;
	scanf("%d",&t);
	while(t--)
	{   count=1;
	    scanf("%d",&n);
	    for(i=1;i<n;i++)
	    {
	        scanf("%d",&a[i]);
	    }
	    
	    if(a[i]<a[i-1])
	    {
	        count++;
	    }
	    printf("%d\n",count);
	}
	
	return 0;
}

Im getting TLE. How can i optimize my code
link for the question: CodeChef: Practical coding for everyone

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

Edit:

int a[5000]

N can be up to 10000.

Edit2:

if(a[i]<a[i-1])

When this is called, i == n, so even if a has space for 10000 elements, this would still be an out-of-bounds access when N=10000.

3 Likes

Any ideas how to optimize for n=10000.
Please help me out as I’m a beginner
Thankyou