Help Ramu Problem - Run Error

http://ide.codingblocks.com/#/s/17552

The problem is giving the correct output for the given test cases but when submitting, it shows “run-error”.
Thank You in advance.

The array size is not as per constraints given , just take an[1000],am[1000] instead of an[50],am[50]