Solution Link:- https://www.codechef.com/viewsolution/28051999
In the Question Description it says Time Limit 5 sec and The value of n ranges to 10e9 which is a lot for O(n) solution i have optimised my solution a lot and thinks it should Pass the Test Case but it’s saying TLE. I want to know How??
g can be up to 20000, and you are looping N (which can be as big as 10^9) times for each g.
Edit:
To be a little more explicit, your solution is O(max_T \times max_g \times max_N) which is far too large; you can almost certainly do it in a much-more-reasonable O(max_T \times max_g)
Edit:
Ah - you’re also using (and leaking) huge amounts of RAM