Optimal Game Strategy 2

When n=10 000 is given in constrainsts, how dp[5000][5000] is helpful instead of dp[10 005][10 005] ?
please guide me

Yes the dp array must be of order 10000 x 10000
dp[5000][5000] would be working because test cases may not be following that constraint

toh mujhe kaise pata chalega ki 5000 lena hai ya phir 6000, instead of 10 000 :frowning:

You just have to follow the constraints. Here test cases were not in accordance with constraints.Even if you make the dp array greater than the size mentioned in the constriants, that will not cause any issue.

Then Why Iā€™m getting MLE with this? https://ide.codingblocks.com/s/280301

Actually we cannot create an integer array of size greater than 10^7(maxm size 1d array allowed is 10^7). That will cause MLE.
So constraints must not be more than this. The problem is with the question. And the constraints must be changed.
I can see that all your test cases were passed. So mark the doubt as resolved if it is so.