1 / 2
Feb 2020

Im getting a segmentation fault on spoj (no error on the local machine). Also im getting an error while defining dp to be a 1000 000 000 length array. Please suggest changes in code asap
thankyou

#include<bits/stdc++.h>
using namespace std;

long long int dp[100000000];

void byte(long long int n)
{
for(long long int j=0;j<=n;j++)
{
dp[j]=max(j,(j/2)+(j/3)+(j/4));

}

}

long long int byto(long long int n)
{
return dp[n];
}
int main()
{
int t=10;
int n;
for(int i=0;i<100000000;i++)
{
dp[i]=i;
}

byte(100000000);

while(cin>>n&&t--)
{
	//long long int dp[n];
	
	
	cout<<byto(n)<<endl;
}

}

  • created

    Jan '20
  • last reply

    Feb '20
  • 1

    reply

  • 565

    views

  • 2

    users

Memory limit: 1536MB

Input

The input will contain several test cases (not more than 10). it is better to compute 10 cases than 1000000000.
For some numbers there is posible to get profit by exchange.
recursion should help maximize profit.