TLE in Fair Cut

link text

can someone explain this problem in O(n*n) running time.
My solution is getting TLE.