I actually have on more question. I can see the issue in my code. But I tried this test case in the codechef website’s IDE (with my original code), and it still runs fine and gives me the correct answer.
Any ideas why it isn’t seeing the error?
[EDIT] It seems that my vector is giving me a value of 0 even when I give it an index out of range. Which makes me think vector handles out of range index’s? But if that is the case, I don’t see where I would have gotten the error originally.
Anyways, I submitted with my fix and got the correct answer. Just don’t understand why I don’t get the run time error you did (with my original code).
An out-of-bounds access with std::vector::operator[] is just Undefined Behaviour by default, so anything can happen. (Contrast with vector::at, which will throw an exception).
The _GLIBCXX_DEBUG flag enables the gcc C++ Standard Library Debug mode and will assert on out-of- bounds access via std::vector::operator[].