Most cost effective way to traverse a set path
Let us number the destinations from $1$ to $N$ and define an array $c[N]$ where $c[i]$ is the minimum cost to travel to destination $1 \leq i \leq N$. We wish to calculate $c[N]$.

It is clear that $c[1] = D_1 \times r$, because if we find ourselves at destination $1$ we can only have gotten there by travelling one destination at a time, instead of travelling five destinations at a time.

The minimum cost of travelling to destination $2$ must be $c[2] = D_2 \times r + c[1]$ for identical reasons ($2 &lt; 5$) as before. We add the minimum cost of reaching destination $1$ to the minimum cost of reaching destination $2$ because we must have travelled from destination $1$ to $2$.

Now we see that for destinations $i \geq 5$, that we could have reached them by travelling through five destinations at a time instead of the previous one destination at a time. This means 
$$c[i] = \min(B + c[i - 5], D_{i} \times r + c[i - 1])$$

Where $c[0] = 0$. From this pattern, we can calculate $c[N]$ in $O(N)$ time complexity.