Golden Trees - SIGSEGV error

Hey I posted the following code for the Golden Trees problem for C++. It is giving me a Runtime error. Could you point out where I a might be going wrong ? newbie :slight_smile:

#include

using namespace std;
int main()
{
//Initialization
int initTax[4] = {0,0,0,0};
int slot1[4]= {0,0,0,0};
int slot2[4] = {0,0,0,0};
int krec[4] = {0,0,0,0};
int noYears[4] = {0,0,0,0};
long long int tempsum=1;
int noSamples = 0;
long long int Tax[3][50];

for(int m=0;m<3;m++)
{
    for(int n=0;n<50;n++)
    {
        Tax[m][n] = 0;
    }
}
//Input
cin>>noSamples;
for(int k=0;k<noSamples;k++)
{
	cin>>initTax[k];
	cin>>slot1[k];
	cin>>slot2[k];
	cin>>krec[k];
	cin>>noYears[k];
}

for(int a=0;a<noSamples;a++)
{
    Tax[a][1]=initTax[a];
    for(int i=1;i<=noYears[a];i++)
    {
        if(i<=slot1[a]+1)
            Tax[a][i]=Tax[a][i-1]+1;
        else if (i<=slot1[a]+slot2[a]+1)
            Tax[a][i] = Tax[a][i-1]*2;
        else
        {
        tempsum =1;
            for(int j=1;j<=krec[a];j++)
            {
                tempsum*=Tax[a][i-j];
                tempsum%=100000007;
            }
            Tax[a][i] = tempsum;

// Tax[a][i]=Tax[a][i]%100000007;
}
}
cout<<Tax[a][noYears[a]]<<endl;
}

return 0;

}

Your code is giving a SIGSEGV error because the size of your tax array per case if only 50 and for cases where n>=50 it tries to make invalid memory reference. You can read abut segmentation fault from here.