To understand Time Limit Exceeded(TLE), understanding how the online judge works will help. The online judge allocates resources like memory and CPU for evaluating every submission. However, to ensure that your submission does not keep running for an infinite time, the online judge has to stop your submission from running after a particular time period. This time period is actually decided by the problem setter and is given as one of the inputs to the online judge. Once the submission program runs for time period the judge system issues a system kill command to the program execution and assigns TLE result to the submission.
The most common reason that you would get a TLE is because your program is too slow. If a problem tells you that N <= 100000, and your program has nested loops each which go up to N, your program will never be fast enough. Read the bounds in the input carefully before writing your program, and try to figure out which inputs will cause your program to run the slowest.
The second most common cause of TLE is that your method of reading input and writing output is too slow. In Java, do not use a Scanner; use a BufferedReader instead. In C++, do not use cin/cout - use scanf and printf instead.
In Python, you could try speeding up your solutions by adding the following two lines to the start of your file:
import psyco
psyco.full()
To see if your method of reading input is fast enough, try solving the Enormous Input Test problem. If you get time limit exceeded, try another method of reading input.
Finally, you may have tested your code on all sorts of large inputs and are sure your code will run inside the time limit. However, CodeChef’s judge may be slower than your computer. It is common for a program to take 2-3 times as long on CodeChef as it does on your computer. The time limits are all attainable(tested by our problem tester), so you will just need to come up with a way of making your algorithm