Pregunta de entrevista de Citadel Securities

asked to solve a problem about dynamic programming