Getting SIGSEGV error

here’s my code: https://www.codechef.com/viewsolution/14198338 my solutions are executing in devc++.but i always get a runtime sIGSEGV error when i try to submit in codechef.As i am beginner,i dont know why, can u explain me?

You have declared array a as-

long long int a[10],n,c,b[10],T,r,s,i,j,k;

And then you are using-

 for(s=0;s<n;s++)
	 scanf("%d",&a[s]);

n can vary from 1 to 10,000 . Since you are going out of bounds (Max size is 10, so max allowed index is 9- while you’re going upto 10,000-1), you are getting the error. Going out of index in an array is the primary reason for this error.

1 Like

i have declared the array with maximum limit. https://www.codechef.com/viewsolution/14199355 it saying it is wrong .but i am getting output in dev c

Try a separate check of 'If size of array is 1, the array is beautiful"

This is not an answer, more like an alternative. Try using vectors. You can dynamically allocate memory using vectors.
I generally prefer using vectors than normal arrays.