Citi Interview Question

Some dp problem with factory lines