Chef And Segments - WA

For the problem Chef And Segments, I followed the editorial and wrote a


(http://www.codechef.com/viewsolution/6827982) accordingly. But it gives me WA. Can anybody help?