Please read the new rule regarding the restriction on the use of AI tools. ×

kalidoss159's blog

By kalidoss159, history, 4 years ago, In English

Contest : Educational Codeforces Round 86 (Rated for Div. 2), Problem — D (Multiple Testcases)

Codeforces submission: https://codeforces.me/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 ?

  • Vote: I like it
  • -5
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

When you do oMap.erase(it->first);, you're essentially erasing it. Then, you try to increment it, which causes undefined behavior. This can be tested by adding printing it->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.