Quote:
How to deal with time limit exceeded in this case?
Simple, you need to find a more efficient algorithm that solve the problem.
You need to understand where your program spend time and thing if another way can be faster.
the tool to see how program spend time is a program profiler.