Why does python throws TLE and cpp does not for the exact same algorithm?

I was competing in today’s Code Ensemble, there I was solving a problem I applied the correct logic but still got TLE, I was fine with it as I thought maybe I could not optimize the code.
When the tournament ended I looked into submission of other coders and found that people have written the exact same logic in CPP but still they got their solution passed.
Well everyone knows that python is slower so doesn’t it makes sense to add that time while evaluating the python code to make things fair.
If there is any way to fix this please let me know.

Try to code in python with fast input output methods , like cpp ,python also have fast io methods -

PyPy Output - Codeforces
Good Input Template for Python Users for Quick and Fast Inputs - Codeforces

2 Likes

use stdin and stdout for fast I/O, otherwise the solution won’t go through

1 Like

Thank you so much, now its working.

1 Like

As others have suggested use FastIO.
Using pypy 3 instead of python 3 is preffered.
Write your code in a function called main and then call main in the end

But most of all if you faced TLE or any other error in a question.
After the contest check out other python programmers code in that question.
By clicking on all submissions,click on AC in result and python 3 or pypy 3 in language(try both),you can see other people’s python code and see what you could have changed.
You could also sort by time by clicking on “Time” in the header of the table so you can see what the fastest codes are.
For example in code ensemble for Help Martha

This is easily exploitable.

Thank you so much for the advise, I will try to implement it.