TLE in Python v/s AC in C++ for the exact same code

As someone who uses both CPP and python for cc, I prefer writing code in python most of the time.
Something that I can’t wrap my head around is that even though extra time is given for python, I still get TLE for the exact same approach and code that gives an AC solution in CPP.

In March Lunchtime 2021, the problem LUNCHTIM put me in a similar situation.
LUNCHTIM PYTHON - 30 PARTIAL
LUNCHTIM CPP SOL - 100 AC

Here are the links for the two submissions made in Python and CPP respectively. The same approach gives TLE for a subtask in python. I understand that the methods I use for I/O are faster in CPP than Python, thus I submitted another solution in python with faster I/O.

Here is the sol:
https://www.codechef.com/viewsolution/44230311

Even this gave me a TLE instead of an AC.
What could possibly be the solution to this… Bypassing this in Python?

same happened with me today in the same question itself. i still don’t get the reason behind this even though time limit is increased for python

Here is your AC Code . I used PYPY3 which is a little faster than Python3.

1 Like

so next time i should use PYPY3 instead of python3 ?

Thank you!
But as far as I know, Python has 5x the time limit and PyPy3 has 2 times the time limit. So theoretically, the code should still give an AC in Python, right?

but may be pypy3 is faster than python3

Here’s my solution in Python. It’s an O(N^2) Solution.

Yes, pypy3 is faster than Python3.

If some approach is giving AC when implemented in One language but gives TLE in another, then it’s not the problem with the language, it’s the problem with the implementation.

PS: There are very rare cases, like the ones here and here, where luck plays an important role.