Not able to clear 3rd subtask

Solution: 48625775 | CodeChef :
Link to my code.
Successfully cleared first 2 subtasks but unable to clear the 3rd one.

Thanks.

Try to optimize , ur code runs in O(N2) complexity