why am i getting TLE?

Why is this giving a TLE error? all seems fine.!
http://www.codechef.com/viewsolution/6604106
please point out the error…

1 Like

You may be getting TLE because you are using an algorithm with complexity O(n^2). As n can be as large as 10^5 you will be doing 10^10 operations which may be exceeding the time limit. Try reducing the time complexity of your algorithm.