bytelandian coins runtym error...help

#include
using namespace std;

int coin[500000000];

int main()
{
long long int n,a,b,c;
long long int d;
coin[1]=1;
coin[0]=0;
cin>>n;
if (n<=500000000)
{

  		for(int i=2;i<=n;++i)
  		{
        	a=i/2;
        	b=i/3;
        	c=i/4;
        	d=coin[a]+coin[b]+coin[c];
        	if(d>i)
        	coin[i]=d;
        	else
        	coin[i]=i;
        
  		}
            cout<<coin[n]<<"\n"; 
  }
  else
  {
           for(int i=2;i<=500000000;++i)
  		{
        	a=i/2;
        	b=i/3;
        	c=i/4;
        	d=coin[a]+coin[b]+coin[c];
        	if(d>i)
        	coin[i]=d;
        	else
        	coin[i]=i;
        
  		}
           a=n/2;
           b=n/3;
           c=n/4;
          	d=coin[a];
                
            d=d+coin[b];
              

            d=d+coin[c];
                
       
           if(d>n)
           cout<<d<<"\n";
           else
           cout<<n<<"\n";
  }
            
            
   
  
  return 0;

}

1 Like

Declaring array of size 5*10^8 would not do the job, so declare a map, see STL classes of cpp. For quick reference, declaration of map can be seen in my submission.