I'm getting "sigsegv" , a runtime error from the following code when i try to run it on codechef while the code works fine on my computer with various test inputs.I've also kept in mind the constraints given in the problem but I'm still unable to debug it. The question is not from any contest but a practice problem . Please point out any mistake you can find .
[Actual codechef question](http://www.codechef.com/problems/SUMTRIAN)

```
#include<stdio.h>

int cash[101][101]={0};
int rec[101][2];
int ri=0;
int sumx(int mat[101][101],int i,int j,int lines)
{
    int n=0,a=0,b=0;
    if(cash[i][j]!=0)
    {
        return cash[i][j];
    }
    else if(i==lines-2)
    {
        n=(mat[i+1][j]>mat[i+1][j+1])?mat[i+1][j]:mat[i+1][j+1];
        cash[i][j]=n+mat[i][j];
        rec[ri][0]=i;
        rec[ri++][1]=j;
        return n+mat[i][j];
    }
    else
    {
        a=sumx(mat,i+1,j,lines);
        b=sumx(mat,i+1,j+1,lines);
        n=(a>b)?a:b;
        cash[i][j]=n+mat[i][j];
        rec[ri][0]=i;
        rec[ri++][1]=j;
        return n+mat[i][j];
    }
}

int main()
{
    int i=0,k=0;
    int lines=0,n=0;
    int r=0;
    int tc=0;
    int mat[101][101];
    scanf("%d",&tc);
    while(tc--)
    {
        scanf("%d",&lines);
        i=0;
        k=0;
        while(i<lines)
        {
            while(k<=i)
            {
                scanf("%d",&mat[i][k]);
                k++;
            }
            k=0;
            i++;
        }
        if(lines==1)
        {
            r=mat[0][0];
        }
        else
        {
            r=sumx(mat,0,0,lines);
        }
        i=0;
        while(i<ri)
        {
            cash[(rec[i][0])][(rec[i][1])]=0;
            rec[i][0]=0;
            rec[i][1]=0;
            i++;
        }
        ri=0;
        printf("%d\n",r);
    }
    return 0;
}

```