HELP ME WITH THIS DYNAMIC PROGRAMMING PROBLEM

Please help me with this problem. Time limit is 1s. Thanks!