Today I spent a few hours solving problem C from the Codeforces Round 917. Most of the time was spent on me not understanding why my code won't work even after spending a lot of time trying to find the bug. It turned out to be a really weird 'bug' which I really can't understand. I managed to fix the code and get AC in the end but it was basically on accident.
I will put comments next to the lines of code that I changed so you can find your way around my messy code a little more easily.
Submission for code 1 right here
Submission for code 2 right here
I know using a vector was redundant but I don't see a single reason why it gives a wrong answer? I really hope someone with more knowledge will be able to help me understand why this was happening so I can avoid a similar bug in the future :D
possible.push_back(d/2);
in the first solution is incorrect. In general, you can't always reach $$$\left\lfloor d/2\right\rfloor$$$ points, for example in this test:The correct value would be $$$\left\lfloor (d-1)/2\right\rfloor$$$. But in the second solution, this line doesn't exist, or in other words, this line of code doesn't help the solution. You can just remove it and the solution will be correct.
Wow, I can't believe I managed to oversee that. Thank you a lot man :D