I was just practicing Question in Codechef and I came through this Question:
I was trying my algo to submit this problem but every time I was getting TLE. I thought there must be a better algo than this. So, I went for the solution and this is the result I got.
My Solution got TLE and in later case it got accepted. Please review it.