But basically it's as such:
fill a list with your "B + C" startpoints and endpoints, sorted like: [B.start, B.end, C.start, C.end, ...]
set a variable (I call it "cursor") to the startpoint of A
in a loop until the list is empty
pop a value from the beginning of the list into a variable (I call it "end")
output a line segment from "cursor" to "end"
pop a value from the beginning of the list into "cursor"
after the loop, output a line segment from "cursor" to the endpoint of line A