my code is giving me time limit exceeded…please help
here is my code http://www.codechef.com/viewsolution/4304786
Consider simple case :
50000 50000 50000
1 4 7 10 13 16 …
2 5 8 11 14 17 …
3 6 9 12 15 18 …
Then first part of your code takes 25*10^8 (N^2).
Second part again N^2.
So you will definitely get TLE. This has an O(NlogN) and a O(N) solution.