Getting segmentation error on a simple DP problem!! Please help!!

Why is this code giving a segmentation error?

Question: http://www.codechef.com/problems/COINS

#include<iostream>
using namespace std;
#define MAX 10000

long long memo[MAX];

long long dp(long long x)
{
    if( x > (x/2 + x/3 + x/4) )
        return x;

    if( x<MAX )
    {
        if( memo[x] == -1 )
            memo[x] = ( dp( x/2 ) + dp( x/3 ) + dp( x/4 ) );

        return memo[x];
    }

    return ( dp( x/2 ) + dp( x/3 ) + dp( x/4 ) );
}

int main()
{

    for(long long i=0;i<MAX;i++)
        memo[i] = -1;

    long long x;
    cin >> x;

    cout << dp(x);

    return 0;
}

well its running fine on online editors, try explicitly declaring array subscript [] as int…

Are you guessing? Because it has worked like this before.

//