Hello,
So, I noticed several times that declaring some variables inside main gives runtime error, usually when they take much space, but still it does not seem it hits memory limit. For example, in these cases 134618509 134618526. In the first one arrays are declared outside main, while in the latter one inside main. Despite the fact they take up the same space the 2nd one gives runtime error. Could you please explain why this happens? Thanks in advance.
Declaring global arrays takes less memory than declaring them inside any function (or for loops or whatsoever). The difference isn't big, but the accepted code hardly passed, so declaring the arrays in the main function won't pass.
That's why I declare global arrays and vectors. they take less memory, they are accessible by all functions without passing them as parameters and they are initiated with zeros instead of random values.
From here:
Also, as he mentioned, you can use vectors instead of an array if you really want to declare it inside main and that doesnt happen. Just take care when youre declaring a vector of vectors because each vector needs to store a pointer, so you can end up passing the memory limit on some problems (like last div3's F)