Hello. I need to make a program which must be executed during 1 second, no more. But my program is being timed out if it need to output a lot of data. I think program does calculation quite fast, problem is in output and do not know how to solve it. I replaced standart input to scanning from a file and have found that execution time is more than 4 seconds.(If you need more data for checking, write)
Ex.:
2
2 1
1 2
10 7
1 4
2 6
3 6
3 7
5 9
6 9
9 10
How do you know that most of the ET is taken up with output? It's just that you have 4 levels of forloop in your code, so that is likely to make for O(n4) so that is quadratic squared - which is not good. Try to aim for algorithms that are some where around O(log n) or O(n)
Is this for an online coding challenge like Euler or Online Judge? If so, the solutions to these are not trivial (brute force doesn't work), so one has to come up with a cunning plan for an algorithm.
@tcs
Just curious: did you use the data from the OPost, or did you get more data from a larger file? I see your input file, just wondering how much data was in it?
Thanks, TheIdeasMan, for info about loops. Yes, this task is for online coding challenge, but in Codeforces area.
I using my own data, because there are no data file or something, just small example. Also there are several limitations for input (T <= 30; 1 <= n, m <= 10000; 1 <= a <= b <= n), but I know when program is being test ultimate data is always in use.
No, no, just wondering how much data you used that's all? :+)
Forgive me for thinking that, but you only had 2 test cases in your output.
Now I am pretty sure you know way way more than me, but if you had run the OP's code with the data in the O Post, it might well run Ok, but if you had 10000 items it might not. Any way I am sure you don't need me to point that out. :+)
Maybe the OP is running the Debug version not the Release? Probably much more likely. I have just written some code to do prime numbers up to 2 million, it took about 15 secs in Debug, and less than 0.5sec in Release mode.