Solution
= Solution
For $0\le k\le n$, sum the marginal stopping <probabilities> over the selected tail:
$$
\boxed{P(X>x_k)=p\sum_{j=k+1}^ng_j+(1-p)\sum_{j=k+1}^nd_j.}
$$
Equivalently it is $p(1-\sum_{j=0}^kg_j)+(1-p)(1-\sum_{j=0}^kd_j)$. At $k=n$, both empty tail sums are zero, as required.