I get WA status and dunno why, because I tested my code massively using this tool -> http://spojtoolkit.com/test/COINS
Here is the link to my code -> https://ideone.com/KnTkB5
As far as I am concerned this issue not seems to be related to memory limits and integers overflow, basically these two issues previously mentioned were my major suspects, so I tell you how I test and checked them:
-
Memory limits. I checked what happen when I set for example:
$test = array();
$test[0] = 1;
echo memory_get_usage();
$test[9999999999999] = 2;
echo memory_get_usage();
There only few bytes more reserved, so not a issue here. The second thing is I set memory limit to the same as in spoj (1536MB), and on my computer still works fine and not any problems
-
Integers overflow this even cannot be a issue if there are 32-bits architecture becasue upper limit is 1000000000 and php MAX_INT on 32-bits architecture is 2147483647 above 2 times more. The max calculated result is: 4243218150 though I dunno how to manage these (if overflow happen here)
So any ideas guys what is wrong with this code? It can sth completely different than these two issues which I described above, some wrong test cases will be also helpful if you can find them. In fact this an interesting issue, because similarity of my code sample to other working examples is staggering. Take this simple one in C++ for example -> http://gargvivekcse12.blogspot.com/2015/08/dp-for-beginners.html