Can anyone explain me why this approach is giving TLE in last 2 test cases.
Here I am maintaining prefix sum and doing iteration for ji .
Link- https://www.codechef.com/viewsolution/17789093
You used two nested loops ,so time complexity of your solution is O(n^2), which will for sure cannot pass those test cases as sum of N in all test cases is \leq{10^6}
Refer to this editorial for alternative approach and my explanation of time comlexity.
MINVOTE EDITORIAL
Please upvote my answer if you got the point as I need 3 karma points to contribute to codechef discuss.