Thought process / editorial

I was solving this problem : cellular network silver and got AC.

I’m looking over the solutions available on the usaco guide. Could someone explain me code of two pointer method more specifically the main idea behind that solution.