Arcesium interview question

Dynamic programming question. (Stock prices in a week)