I don’t think the explanation for 5.7 is correct. It states “To combine these two, we compute M[i] = F[i] + B[i] (since the second buy must happen after the first sell)” F is [0, 0, 2, 2, 3, 3, 6, 6, 7] and B is [7, 7, 7, 7, 7, 7, 2, 2, 0] so I don’t see how they got M is [7, 7, 7, 9, 9, 10, 5, 8, 6]. M[i] = F[i] + B[i] would yield [7, 7, 9, 9, 10, 10, 8, 8, 7].
I think they meant M[i] = F[i] + B[i+1] but then that leaves the question of where does the extra 7 at the beginning come from?