Codeforces Round #632 (Div. 2) (Problem C) Help needed

Problem: Problem - C - Codeforces
Hi Brute force for this problem is obvious(n^2),but I think this problem can be solved using 2-pointer but I am not able to think of the solution.I have read the editorial but not able to understand completely.
Any help would be appreciated.

go through this thread,this guy has explained in the best way

1 Like