MINVOTE(March Long Challenge)

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- CodeChef: Practical coding for everyone

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.