TLE in TASHIFT

my solution is passing all the cases, except last two.
where is the error?
https://www.codechef.com/viewsolution/9193334

Because Your Solution Has O(N^2) time complexity which is definitely not enough to pass all test case.
You may apply small optimizations such as using scanf/printf instead of cin/cout but i don’t think that would help much.