Why difference in C++ and Python programs?

Revision en1, by IngaleAnkur10, 2019-03-13 16:45:31

I tried this problem: https://codeforces.net/contest/1136/problem/D.
And came up with a solution similar to the solution in the editorial.
But I first submitted my Python code in both Python3 and PyPy3 and had TLE.
But when I submitted an ALMOST equivalent code in C++, it got accepted.
I wonder what's wrong in my python code or is it the compiler's/interpreter's doing?

Python Code : https://codeforces.net/contest/1136/submission/51256343.
C++ code: https://codeforces.net/contest/1136/submission/51257855

Tags #c++, #python 3, #pypy3, #tle

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English IngaleAnkur10 2019-03-13 16:49:22 105 Tiny change: 'n/51257855' -> 'n/51257855. \n \nThanks in advance.' (published)
en1 English IngaleAnkur10 2019-03-13 16:45:31 572 Initial revision (saved to drafts)