Look at the transition: . This is exactly the sliding window maximum problem! The window contains the last DP values.
You already know how to solve that in per query using a monotonic decreasing deque. Apply it directly to the DP values. As you compute , maintain a deque of indices sorted by decreasing values. The front gives you the maximum value in the valid range.