Time limit exceeded..

my solution for lucky array(medium section) says time limit exceeded…please tell me what changes should i do to remove this error…
here is the link : http://www.codechef.com/viewsolution/3144596

//