C++ solution throws bad alloc


Comment body goes here.


set B to be the minimum of A.size() and B.When B is bigger than A.size() then we are just simply copying the values we have calculated above;


Always we need just the above dp array, so we can solve the problem using 2 arrays


But, can you tell why c++ throws bad alloc error?..It runs fine when custom tested…