https://codeforces.com/problemset/problem/1354/B

please give me a dp solution for this problem i solved it using two pointers but struggling to form dp solution (i am new to dp so learning dp );