Problem: Grab a ladder.
for(i=0; i<cases; i++)
From the CodeChef wiki:
“A SIGSEGV is an error(signal) caused by an invalid memory reference or a segmentation fault. You are probably trying to access an array element out of bounds or trying to use too much memory. Some of the other causes of a segmentation fault are : Using uninitialized pointers, dereference of NULL pointers, accessing memory that the program doesn’t own.”
I’m not really a C programmer, but as far as I can see, you really don’t need the two files, test.txt and out.txt (memory that the program doesn’t own). CodeChef problems require you to simply read and write from the console.
Further if you’re using C++, may I suggest using std::vector instead of malloc.
The error is because you are not type casting the allocated memory. By default malloc allocates char.
So just replace this statement
c1 =malloc(n*sizeof(int)); by
c1 = (int *) malloc ( n * sizeof( int ) );
Hope it works!
Also, unlike many other sites(like code jam) you have to take your input in standard input and give output to standard output, not to any file.