C3 AI interview question

a dp problem which is somewhat diffucult