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.
Basically check the size of the array a and b. Make them at least as big as the maximum possible value of m and n.
Another Possibility is that the size of array a is too much. Make sure that the number of elements in a do not exceed 10^6.
If you think that your problem requires that big array, maybe you are not using the correct algorithm.
Note: Check STL in C++, you may find your solution
what are the max values for n and m??
It is very little information. Ask questions clearly.