Since we are asked to find shortest path, we can use Dijkstra algorithm. We can see how to do it here.
'l' roads and 'm' segments can be viewed as a graph with 'l' edges and 'm' nodes. Now, there is an additional constraint here that we cannot simply consider all paths but any path must have continuous uphill paths followed by continuous downhill paths. In order to do this we can run Dijkstra algorithm twice,
- from the home as source and only considering uphill paths (from any node) till end, we update the shortest distance to each node, let it be $U_{i}.$
- with the work as source and only considering downhill paths (towards any node) till home and again update the shortest distance to each node, let it be $D_i.$
Now, all we need to do is to visit each node and do $U_i + D_i$ and finally take the minimum value of it. The node corresponding to it will be the point where uphill path changes to downhill one.
Complexity = Shortest path complexity + $O(m)$
$= O(l + m \log m) + O(m)$
$ = O(l + m \log m).$