Contest : Educational Codeforces Round 86 (Rated for Div. 2), Problem — D (Multiple Testcases)
Codeforces submission: https://codeforces.net/contest/1342/submission/78251331
Other IDEs : https://ide.geeksforgeeks.org/eY2UpkI1FI, https://www.onlinegdb.com/B1QJjR7FL
I tried the same in my offline IDE as well. The output is just as expected. On the other hand, codeforces shows a different output. Any idea as to why this happens ?
When you do
oMap.erase(it->first);
, you're essentially erasingit
. Then, you try to incrementit
, which causes undefined behavior. This can be tested by adding printingit->first
every time you run the inner for loop. CodeForces and GeeksForGeeks will give different outputs.Also, I don't think using a map to store values of m will make your code any faster, since the maximum values of n and k are the same. So using a map adds an unnecessary log n factor.