Div 3 Codeforces

https://codeforces.com/contest/999/problem/F?f0a28=1

I can’t understand the dp intuition and transitions