Wall of Mordor --- Mission Impossible#11847

Wall of Mordor --- Mission Impossible (Editorial)

Sort towers by ascending and sweep left → right:

  1. On visiting tower (x_i,w_i,r_i), add it to a multiset/priority-queue keyed by right endpoint x_i+r_i.

  2. Before processing, remove any element with x_i> x_j+r_j (its radius no longer reaches ).

  3. Maintain the current sum of active weights (alertness) S_L(i) and a container that returns in O(\log n) the maximum weight among actives except itself, let max_L(i) be this maximum. Disabling that candidate minimizes and maximizes .

Repeat symmetrically sweeping right → left, tracking S_R(i) and max_R(i) by left endpoints x_i-r_i.

For tower the two best candidates give

\operatorname{eff}(P,Q)=S_L(i)+S_R(i)-\max\bigl\{max_L(i),\,max_R(i)\bigr\}.

Enumerate all , keep the global maximum and the pair . Overall complexity O(n\log n).