C3 AI Interview Question

a dp problem which is somewhat diffucult