# Service Stations on a Line: The Rightmost Station as a State This is the setter's endpoint-placement DP, implemented in [alternative.cpp](alternative.cpp) for the full constraints. Sort the homes as $x_1\le\cdots\le x_N$ . A station can be moved to the median of its consecutive service group, so restricting stations to home coordinates retains an optimum. ## Cost between two stations If consecutive stations lie at $x_i,x_j$ , the intermediate homes contribute $$W(i,j)=\sum_{i