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